php html_entity_decode 标签没有闭合,php – strip_tags和html_entity_decode组合无法按预期工作...
我從昨天起就一直在與這個(gè)問題作斗爭(zhēng) – 不幸的是無濟(jì)于事(并非完全沒有,我找到了某種解決方法),經(jīng)過一些研究和重讀文檔后,我仍然沒有多少目瞪口呆和困惑.
讓我們假設(shè)有一個(gè)丑陋的字符串,它已經(jīng)具有正確的html編碼的特殊字符.像這樣 :
$exampleString = '<div id="dynamic2"> <div
id="iStoreProductLongDescription" class="iStoreBox">
<div class="iStoreBoxWrapper"> <div
class="iStoreBoxContent"> <p style="text-
align:justify;"> </p> <p style="text-
align:justify;"><span style="font-
size:large;"><span> Just a bunch of text here, at
the end. yedyedyed';
現(xiàn)在我想把這個(gè)字符串輸出為一個(gè)簡(jiǎn)單,干凈的字符串,所以首先我需要將它轉(zhuǎn)換為html標(biāo)簽,然后剝離標(biāo)簽.所以我猜以下鏈應(yīng)該有效:
$result = strip_tags(htmlspecialchars_decode($exampleString));
但事實(shí)并非如此,在網(wǎng)絡(luò)的來源中echo $的結(jié)果是:
<div id="dynamic2"> <div id="iStoreProductLongDescription" class="iStoreBox"> <div class="iStoreBoxWrapper"> <div class="iStoreBoxContent"> <p style="text-align:justify;"> </p> <p style="text-align:justify;"><span style="font-size:large;"><span> Just a bunch o text here, at the end. yedyedyed
在用戶輸出中,html標(biāo)簽是可見的并且保持不變.但是,當(dāng)我做這樣的事情時(shí):
$result = strip_tags(html_entity_decode(htmlspecialchars_decode($exampleString)));
然后它像魅力一樣工作,并向用戶輸出所需的字符串,同樣在web源中:
Just a bunch o text here, at the end. yedyedyed
問題是 – 為什么不
strip_tags(htmlspecialchars_decode($exampleString));
工作(我認(rèn)為)它應(yīng)該工作?
任何見解都非常感激.
干杯
解決方法:
如果你仔細(xì)觀察,你會(huì)看到你有
&放大器;放大器; LT;并且它不是& lt;.
所以,你首先htmlspecialchars_decode只是轉(zhuǎn)換
&放大器;放大器; LT;到& lt;
這肯定是一個(gè)特殊的實(shí)體,以后可以用第二次運(yùn)行的htmlspecialchars_decode(或html_entity_decode)解碼為
標(biāo)簽:php,html
來源: https://codeday.me/bug/20190609/1201958.html
總結(jié)
以上是生活随笔為你收集整理的php html_entity_decode 标签没有闭合,php – strip_tags和html_entity_decode组合无法按预期工作...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: matlab signal工具箱,免费试
- 下一篇: 新浪微博杨卫华 PHP,构建高性能的微博