HTML输出核心类
API - Core_HTML
- HTML::$attribute_order
- HTML::$windowed_urls
- HTML::chars - Convert special characters to HTML entities. All untrusted content
- HTML::entities - Convert all applicable characters to HTML entities. All characters
- HTML::anchor - Create HTML link anchors. Note that the title is not escaped, to allow
- HTML::file_anchor - Creates an HTML anchor to a file. Note that the title is not escaped,
- HTML::obfuscate - Generates an obfuscated version of a string. Text passed through this
- HTML::email - Generates an obfuscated version of an email address. Helps prevent spam
- HTML::mailto - Creates an email (mailto:) anchor. Note that the title is not escaped,
- HTML::style - Creates a style sheet link element.
- HTML::script - Creates a script link.
- HTML::image - Creates a image link.
- HTML::attributes - Compiles an array of HTML attributes into an attribute string.
Convert special characters to HTML entities. All untrusted content should be passed through this method to prevent XSS injections.
echo HTML::chars($username);
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$value |
string |
String to convert | |
$double_encode |
boolean |
Encode existing entities | bool true |
string
Convert all applicable characters to HTML entities. All characters that cannot be represented in HTML with the current character set will be converted to entities.
echo HTML::entities($username);
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$value |
string |
String to convert | |
$double_encode |
boolean |
Encode existing entities | bool true |
string
Create HTML link anchors. Note that the title is not escaped, to allow HTML elements within links (images, etc).
echo HTML::anchor('/user/profile', 'My Profile');
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$uri |
string |
URL or URI string | |
$title |
string |
Link text | null |
$attributes |
array |
HTML anchor attributes | null |
$protocol |
string |
Use a specific protocol | null |
string
Creates an HTML anchor to a file. Note that the title is not escaped, to allow HTML elements within links (images, etc).
echo HTML::file_anchor('media/doc/user_guide.pdf', 'User Guide');
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$file |
string |
Name of file to link to | |
$title |
string |
Link text | null |
$attributes |
array |
HTML anchor attributes | null |
$protocol |
string |
Non-default protocol, eg: ftp | null |
string
Generates an obfuscated version of a string. Text passed through this method is less likely to be read by web crawlers and robots, which can be helpful for spam prevention, but can prevent legitimate robots from reading your content.
echo HTML::obfuscate($text);
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$string |
string |
String to obfuscate |
string
Generates an obfuscated version of an email address. Helps prevent spam robots from finding email addresses.
echo HTML::email($address);
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$email |
string |
Email address |
string
Creates an email (mailto:) anchor. Note that the title is not escaped, to allow HTML elements within links (images, etc).
echo HTML::mailto($address);
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$email |
string |
Email address to send to | |
$title |
string |
Link text | null |
$attributes |
array |
HTML anchor attributes | null |
string
Creates a style sheet link element.
echo HTML::style('media/css/screen.css');
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$file |
string |
File name | |
$attributes |
array |
Default attributes | null |
$index |
boolean |
Include the index page | bool false |
string
Creates a script link.
echo HTML::script('media/js/jquery.min.js');
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$file |
string |
File name | |
$attributes |
array |
Default attributes | null |
$index |
boolean |
Include the index page | bool false |
string
Creates a image link.
echo HTML::image('media/img/logo.png', array('alt' => 'My Company'));
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$file |
string |
File name | |
$attributes |
array |
Default attributes | null |
$index |
unknown |
bool false |
string
Compiles an array of HTML attributes into an attribute string. Attributes will be sorted using HTML::$attribute_order for consistency.
echo '<div'.HTML::attributes($attrs).'>'.$content.'</div>';
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$attributes |
array |
Attribute list | null |
string