简体   繁体   English

如何通过PHP将特殊字符转换为html单词?

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

I have so many special characters like this in mysql data while I am displaying in xml file through php.当我通过php在xml文件中显示时,我在mysql数据中有很多这样的特殊字符。

—,”,’,“...etc

I want to convert as a original words using php.我想使用 php 转换为原始单词。

您正在寻找html_entity_decode

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

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

You should go with htmlspecialchars_decode as html_entity_decode is a slighter - overkill version .你应该使用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