1
4

1 回答 1

0
<!doctype html>

<html lang="en">
<head>
    <title>String Cleansing</title>
</head>
<body>
<?php
echo '<pre>';

// The below are the strings
echo $string_with_htmlent =
     "a detail of The School of Athens<!-- this should link to an article about the famous artwork -->, a fresco by Raphael";

echo '<br>';

echo $string_unicode = 
     "Aristotle by Francesco Hayez (1791";
?>&acirc;&euro;&quot;
<?php 

echo $string_unicode_c = "1882)";    
echo '<br>';

// The below is how you fixed
echo $a = html_entity_decode($string_with_htmlent); echo '<br>';

echo $b = htmlentities($string_unicode.$string_unicode_c);

echo '<br>';

// The below is how I code and you expect
$clean = $string_with_htmlent.' '.$string_unicode.' '.$string_unicode_c; 

var_dump(filter_var($clean,FILTER_SANITIZE_STRING));

echo '</pre>';
?>
</body>
</html>

替代html_entity_decodehtmlentitiesFILTER_SANITIZE_STRING。使用一个内置功能修复所有 html 实体代码和特殊字符。

于 2014-12-09T11:25:18.850 回答