我想转换空格、单引号/双引号、换行符等所有内容。
这是一个示例输入(感谢som_nangia):
Escape Check < "escape these" > <“and these”> <html><tr><td></td></tr></html> 'these will need escaping too' ‘ so will these’ <script> </script>
以下是我正在考虑的选项:
<pre>Escape Check < "escape these" > <“and these”> <html><tr><td></td></tr></html> 'these will need escaping too' ‘ so will these’ <script> </script></pre>
/**
* Encoding html special characters, including nl2br
* @param string $original
* @return string
*/
function encode_html_sp_chars($original) {
$table = get_html_translation_table(HTML_ENTITIES);
$table[' '] = ' ';
$encoded = strtr($original, $table);
return nl2br($encoded);
}
我已经尝试过htmlspecialchars和htmlentities,但它们都没有编码空格。