esc_html()(轉(zhuǎn)義 Html)
esc_html() 函數(shù)用來(lái)轉(zhuǎn)義 Html 代碼,讓 Html 代碼不轉(zhuǎn)義。
用法
esc_html( $text );
參數(shù)
$text
(字符串)(必須)要轉(zhuǎn)義的字符串。
默認(rèn)值:None
返回值
(字符串)返回轉(zhuǎn)義后的字符。
例子
echo esc_html( '<a href="http://www.example.com/">A link</a>' );
上邊的代碼將輸出:
WordPress 函數(shù):esc_html()(轉(zhuǎn)義 Html)
(為了防止瀏覽器轉(zhuǎn)碼,我直接截了一張圖)
更多
此函數(shù)位于:wp-includes/formatting.php
esc_url()(過(guò)濾鏈接)
很多 URL 會(huì)有一些小錯(cuò)誤,用 esc_url() 函數(shù)可以屏蔽或者修正這些錯(cuò)誤,并且可以拒絕不安全的協(xié)議。
esc_url() 函數(shù)的工作內(nèi)容:
默認(rèn)拒絕不是下面協(xié)議的 URL:defaulting to http、https、ftp、ftps、mailto、news、irc、gopher、nntp、feed 和 telnet
刪除無(wú)效字符和危險(xiǎn)的字符
將字符轉(zhuǎn)換成 HTML 實(shí)體字符
使用方法
esc_url( $url, $protocols, $_context );
參數(shù)
$url
(字符串)(必須)要被過(guò)濾的 URL.
默認(rèn)值:None
$protocols
(數(shù)組)(可選)可以接收協(xié)議的數(shù)組,如果沒(méi)有設(shè)置,則默認(rèn)為:defaulting to http、https、ftp、ftps、mailto、news、irc、gopher、nntp、feed 和 telnet.
默認(rèn)值:None
$_context
(字符串)(可選)如何返回 URL.
默認(rèn)值:(字符串)display
返回值
(字符串)返回過(guò)濾后的鏈接。
例子
<?php echo esc_url( 'www.endskin.com' );//輸出:http://www.endskin.com ?>
更多
此函數(shù)位于:wp-includes/formatting.php
新聞熱點(diǎn)
疑難解答
圖片精選