Manual:HtmlArmor.php
Appearance
MediaWiki バージョン: | ≧ 1.28 Gerrit change 284750 |
MediaWiki ファイル: HtmlArmor.php | |
---|---|
場所: | includes/libs/ |
ソース コード: | master • 1.42.3 • 1.41.4 • 1.39.10 |
クラス: | HtmlArmor |
HtmlArmor is a small utility class for situations where you want to accept a parameter of text that is normally escaped, but in some cases needs to accept raw HTML.
使用法
/**
* @param string|HtmlArmor $text
* @return string
*/
function fooBar( $text ) {
$html = HtmlArmor::getHtml( $text );
return "<stuff>$html</stuff>";
}
In the above example, the $text
parameter can either be a to-be-escaped string, or an HtmlArmor object that should remain the same.
The HtmlArmor::getHtml()
function will take care of the escaping for you, providing you with content you know that is safe HTML.
fooBar( "this will be <b>escaped!</b>" );
// <stuff>this will be <b>escaped!</b></stuff>
fooBar( new HtmlArmor( "this will <i>not</i> be <b>escaped!</b>" ) );
// <stuff>this will <i>not</i> be <b>escaped!</b></stuff>"