Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
375 views
in Technique[技术] by (71.8m points)

php - Same strings but var_dump() says one is 5 characters longer

I have 2 strings, when I do var_dump() I see one string is 5 characters longer than the other one.

I guess this is because in the first string, the ' (quote) is seen as ' or ' (but I am not sure about this).

string(15) "i'm a bird" 
string(10) "i'm a bird" 

I want the first string to have 10 chars aswell.

I already tried htmlspecialchars(), htmlspecialchars() with ENT_QUOTES, htmlspecialchars() with ENT_NOQUOTES, utf8_decode(), utf8_encode(), ...

It still stays a string(15).

Someone knows how to do it?

EDIT: @ Mathieu Imbert: When I look at the page source, I see it like this:

string(15) "i'm a bird"

SOLUTION:

EDIT: Thanks PeeHaa !! You code @ http://codepad.viper-7.com/pvHCwH fixed it!

html_entity_decode($title, ENT_QUOTES); 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you want the first string to be 10 chars aswell, you need to DECODE the encoded value in the string. Check html_entity_decode

The example you give would make the second string also larger then 10 chars.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...