簡體   English   中英

如何通過PHP將特殊字符轉換為html單詞?

[英]How to convert special characters to html words through PHP?

當我通過php在xml文件中顯示時,我在mysql數據中有很多這樣的特殊字符。

—,”,’,“...etc

我想使用 php 轉換為原始單詞。

您正在尋找html_entity_decode

$s = ' —,”,’,“';
echo html_entity_decode($s);

您只需要http://www.php.net/manual/en/function.html-entity-decode.php

你應該使用htmlspecialchars_decode因為html_entity_decode是一個稍微矯枉過正的版本

<?php
$s = '&mdash;,&rdquo;,&rsquo;,&ldquo;';
echo htmlspecialchars_decode($s);

OUTPUT :

—,”,’,“
<?php
$orig = "I'll \"walk\" the <b>dog</b> now";

$a = htmlentities($orig);

  echo $a; // I'll &quot;walk&quot; the &lt;b&gt;dog&lt;/b&gt; now

$b = html_entity_decode($a);

  echo $b; // I'll "walk" the <b>dog</b> now
?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM