1 回答

TA貢獻(xiàn)1816條經(jīng)驗(yàn) 獲得超4個(gè)贊
如果您需要將 HTML 保存到數(shù)據(jù)庫(kù),您可以使用兩種不同的方式
使用準(zhǔn)備好的語(yǔ)句。
對(duì)所有標(biāo)簽和其他特殊符號(hào)進(jìn)行編碼,例如通過(guò)
htmlentities
或htmlspecialchars
。
示例htmlentities
:
<?php
? ? $link = '<a >Check that</a>';
? ? echo(htmlentities($link, ENT_QUOTES|ENT_HTML5));
? ? // output:
? ? /*
? ? <a href="https://stackoverflow.com/">Check that</a>
? ? */
?>
用于解碼為 HTML 使用html_entity_decode
<?php
? ? $encoded = '<a href="https://stackoverflow.com/">Check that</a>';
? ? echo(html_entity_decode($encoded, ENT_QUOTES|ENT_HTML5));
? ? // output
? ? /*
? ? <a >Check that</a>
? ? */
?>
示例htmlspecialchars:
<?php
? ? $link = '<a >Check that</a>';
? ? echo(htmlspecialchars($link, ENT_QUOTES|ENT_HTML5));
? ? // output
? ? /*
? ? <a href="https://stackoverflow.com/">Check that</a>
? ? */
?>
對(duì)于解碼htmlspecialchars:
<?php
? ? $encoded = '<a href="https://stackoverflow.com/">Check that</a>';
? ? echo(htmlspecialchars_decode($encoded, ENT_QUOTES|ENT_HTML5));
? ? // output
? ? /*
? ? <a >Check that</a>
? ? */
?>
- 1 回答
- 0 關(guān)注
- 201 瀏覽
添加回答
舉報(bào)