鏈接研究之:應用ヶ輛,以剝離標籤
How do you apply htmlentities selectively? 和 PHP function to strip tags, except a list of whitelisted tags and attributes
他們接近,但並不如預期。
我試過了什麼?
<?php
define('CHARSET', 'UTF-8');
define('REPLACE_FLAGS', ENT_HTML5);
function htmlcleaned($string) {
$string = htmlentities($string);
return str_replace(
array("<i>", "<b>", "</i>", "</b>", "<p>", "</p>"),
array("<i>", "<b>", "</i>", "</b>", "<p>", "</p>"), $string);
}
echo htmlcleaned("<p>How are you?</p><p><b>This is bold</b></p><p><i>This is italic</i></p><p><u>This is underline</u></p><p><br></p><ul><li>This is list item 1</li><li>This is list item 2</li></ul><p><br></p><ol><li>This is ordered list item 1</li><li>This is ordered list item 2</li></ol><p><a target='_blank' style='color: #1c5c76;' href='http://www.google.com'>http://www.google.com</a></p><p>This is plain text again.<br></p><script>alert('attempt csrf');</script><p><p>This is P tag example</p></p>");
?>
我想實現什麼?
如果輸入的是:
<b><script>alert("something");</script></b>
那麼輸出將是:
<b><script&rt;("something");</script$rt;</b>
有沒有具體的黑名單,但有一個特定的白名單。
如果第二個包含您可以嘗試適應的解決方案,您列出「研究鏈接」的原因是什麼? –
http://stackoverflow.com/a/36840765/476 – deceze
@MarcinOrlowski再次閱讀我的問題,你可能知道:) – Karma