转换&到PHP中的撇号 [英] Convert ' to an apostrophe in PHP
问题描述
我的数据中有很多HTML实体(& bull;
... etc),包括&
。我只是想把它转换成相当的字符。
我假设htmlspecialchars_decode()可以工作,但是 - 没有运气。我想这样做:
echo htmlspecialchars_decode('They& amp; amp; amp; ;在这里。');
但它会返回: 编辑: 我也试过html_entity_decode() ,但它似乎不起作用: 也会返回: 既然 在PHP 5.4.0中,引入额外的标记来处理不同的语言,每种语言都包含 这意味着你可以这样做: 您将需要 在PHP 5.4.0之前,您需要使用 str_replace : My data has many HTML entities in it ( I assumed htmlspecialchars_decode() would work, but - no luck. Thoughts? I tried this: But it returns: Edit: I've also tried html_entity_decode(), but it doesn't seem to work: also returns: Since In PHP 5.4.0, extra flags were introduced to handle different languages, each of which includes This means you can do something like this: You will need both Prior to PHP 5.4.0, you'll need to use str_replace:
这篇关于转换&到PHP中的撇号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!他们& re这里。$ c
$ b
$ p $ echo html_entity_decode('They&'re here。')
他们在这里。
&< / code>不是HTML 4.01的一部分,在默认情况下,不会转换为
'
。
& apos ;
作为一个实体。
echo html_entity_decode('They&'re here。',ENT_QUOTES | ENT_HTML5);
ENT_QUOTES
和双引号)和 ENT_HTML5
(或任何非
echo str_replace('&';','','他们& 。');
•
...etc) including '
. I just want to convert it to its character equivalent.echo htmlspecialchars_decode('They're here.');
They're here.
echo html_entity_decode('They're here.')
They're here.
'
is not part of HTML 4.01, it's not converted to '
by default.'
as an entity.echo html_entity_decode('They're here.', ENT_QUOTES | ENT_HTML5);
ENT_QUOTES
(convert single and double quotes) and ENT_HTML5
(or any language flag other than ENT_HTML401
, so choose the most appropriate to your situation). echo str_replace(''', "'", 'They're here.');