在PHP中可以通過(guò)使用“htmlentities()”函數(shù)轉(zhuǎn)義HTML字符,該函數(shù)的作用是將字符轉(zhuǎn)換為HTML轉(zhuǎn)義字符,使用方法只需將HTML傳入該函數(shù),其返回值是轉(zhuǎn)義后的HTML字符。
語(yǔ)法
htmlentities ( string $string [, int $flags = ENT_COMPAT | ENT_HTML401 [, string $encoding = ini_get("default_charset") [, bool $double_encode = true ]]] ) : string使用示例
<?php $str = "A 'quote' is <b>bold</b>"; // 輸出: A 'quote' is <b>bold</b> echo htmlentities($str); // 輸出: A 'quote' is <b>bold</b> echo htmlentities($str, ENT_QUOTES); ?>
<?php $str = "\x8F!!!"; // 輸出空 string echo htmlentities($str, ENT_QUOTES, "UTF-8"); // 輸出 "!!!" echo htmlentities($str, ENT_QUOTES | ENT_IGNORE, "UTF-8"); ?>
以上便是《PHP如何轉(zhuǎn)義HTML字符?》的全部?jī)?nèi)容,網(wǎng)站建設(shè)好后不僅需要持續(xù)的內(nèi)容維護(hù),還需要SEO優(yōu)化和一定的網(wǎng)絡(luò)推廣工作,希望我們的內(nèi)容能幫助到網(wǎng)站制作的朋友。
西安尊云科技云建站,配備網(wǎng)站空間,贈(zèng)送域名,再搭配精美模板,快速搭建網(wǎng)站。而且價(jià)格便宜,超高性價(jià)比;買2年得3年。