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_decodeとの代替htmlentitiesですFILTER_SANITIZE_STRING。すべての html エンティティ コードと特殊文字を 1 つの組み込み関数で修正します。

于 2014-12-09T11:25:18.850 に答える