相同的字符串,但var_dump()表示一个多了5个字符 [英] Same strings but var_dump() says one is 5 characters longer
问题描述
我有2个字符串,当我执行var_dump()
时,我看到一个字符串比另一个字符串长5个字符.
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"
我希望第一个字符串也包含10个字符.
I want the first string to have 10 chars aswell.
我已经尝试过htmlspecialchars()
,htmlspecialchars()
和ENT_QUOTES
,htmlspecialchars()
和ENT_NOQUOTES
,utf8_decode()
,utf8_encode()
,...
I already tried htmlspecialchars()
, htmlspecialchars()
with ENT_QUOTES
, htmlspecialchars()
with ENT_NOQUOTES
, utf8_decode()
, utf8_encode()
, ...
它仍然是string(15)
.
有人知道该怎么做吗?
@ Mathieu Imbert:当我查看页面源代码时,我看到的是这样的:
@ Mathieu Imbert: When I look at the page source, I see it like this:
string(15) "i'm a bird"
解决方案:
SOLUTION:
谢谢PeeHaa!您已对@ http://codepad.viper-7.com/pvHCwH 进行了编码! >
Thanks PeeHaa !! You code @ http://codepad.viper-7.com/pvHCwH fixed it!
html_entity_decode($title, ENT_QUOTES);
推荐答案
如果您希望第一个字符串也为10个字符,则需要DECODE
字符串中的编码值.检查 html_entity_decode
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
您给出的示例将使第二个字符串也大于10个字符.
The example you give would make the second string also larger then 10 chars.
这篇关于相同的字符串,但var_dump()表示一个多了5个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!