html class函数,wordpress函数sanitize_html_class()用法示例
sanitize_html_class( string $class, string $fallback = '' )
Sanitizes an HTML classname to ensure it only contains valid characters.
描述
Strips the string down to A-Z,a-z,0-9,_,-. If this results in an empty string then it will return the alternative value supplied.
参数
$class
(string)
(Required)
The classname to be sanitized
$fallback
(string)
(Optional)
The value to return if the sanitization ends up as an empty string. Defaults to an empty string.
Default value: ''
返回值
(string) The sanitized value
源代码
File: wp-includes/formatting.php
function sanitize_html_class( $class, $fallback = '' ) {
//Strip out any % encoded octets
$sanitized = preg_replace( '|%[a-fA-F0-9][a-fA-F0-9]|', '', $class );
//Limit to A-Z,a-z,0-9,_,-
$sanitized = preg_replace( '/[^A-Za-z0-9_-]/', '', $sanitized );
if ( '' == $sanitized && $fallback ) {
return sanitize_html_class( $fallback );
}
/**
* Filters a sanitized HTML class string.
*
* @since 2.8.0
*
* @param string $sanitized The sanitized HTML class.
* @param string $class HTML class before sanitization.
* @param string $fallback The fallback string.
*/
return apply_filters( 'sanitize_html_class', $sanitized, $class, $fallback );
}
更新日志
Version
描述
2.8.0
Introduced.
相关函数
Uses
wp-includes/formatting.php:
sanitize_html_class()
wp-includes/formatting.php:
sanitize_html_class
wp-includes/plugin.php:
apply_filters()
Used By
wp-admin/includes/class-wp-media-list-table.php:
WP_Media_List_Table::column_title()
wp-admin/includes/class-wp-press-this.php:
WP_Press_This::html()
wp-includes/link-template.php:
_navigation_markup()
wp-login.php:
login_header()
wp-admin/includes/class-wp-screen.php:
WP_Screen::add_help_tab()
wp-admin/includes/class-wp-plugin-install-list-table.php:
WP_Plugin_Install_List_Table::display_rows()
wp-admin/includes/template.php:
iframe_header()
wp-admin/includes/media.php:
attachment_submitbox_metadata()
wp-admin/menu-header.php:
_wp_menu_output()
wp-includes/formatting.php:
sanitize_html_class()
wp-includes/post-template.php:
get_post_class()
wp-includes/post-template.php:
get_body_class()
wp-includes/media.php:
gallery_shortcode()
wp-includes/media.php:
img_caption_shortcode()
wp-includes/comment-template.php:
get_comment_class()
wp-includes/class-wp-editor.php:
_WP_Editors::editor_settings()
Show 11 more used by
Hide more used by
Skip to note content
You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note
Contributed by Codex
Basic Example
// If you want to explicitly style a post, you can use the sanitized version of the post title as a class
$post_class = sanitize_html_class( $post->post_title );
echo '
?>
Created this function to help escape multiple HTML classes, you can give it an array of classes or a string of them separated by a delimiter:
if( ! function_exists("sanitize_html_classes") ){
function sanitize_html_classes($classes, $sep = " "){
$return = "";
if(!is_array($classes)) {
$classes = explode($sep, $classes);
}
if(!empty($classes)){
foreach($classes as $class){
$return .= sanitize_html_class($class) . " ";
}
}
return $return;
}
}
html class函数,wordpress函数sanitize_html_class()用法示例相关推荐
- php 字符串函数 教程_php字符串函数 str类常见用法示例
本文实例讲述了php字符串函数 str类常见用法.分享给大家供大家参考,具体如下: str_split(string, leg);//将一个字符 串转换为数组,参数1:要被转换的字符串,参数2:每 段 ...
- php中mimes函数,wordpress函数check_upload_mimes()用法示例
check_upload_mimes( array $mimes ) Check an array of MIME types against a whitelist. 描述 WordPress sh ...
- PHP Calendar 函数,wordpress函数get_calendar()用法示例
get_calendar( bool $initial = true, bool $echo = true ) Display calendar with days that have posts a ...
- C语言中time函数的定义及用法示例
头文件time.h @函数名称: localtime 函数原型: struct tm *localtime(const time_t *timer) 函数功能: 返回一个以tm结构表达的机器时间信息 ...
- php theexcerpt,wordpress的excerpt()函数的用法示例
本篇文章给大家带来的内容是关于wordpress的excerpt()函数的用法示例,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 问题:在wordpres中的single页面,本身引 ...
- python 装饰器 参数-python函数装饰器之带参数的函数和带参数的装饰器用法示例...
本文实例讲述了python函数装饰器之带参数的函数和带参数的装饰器用法.分享给大家供大家参考,具体如下: 1. 函数带多个参数 # 普通的装饰器, 打印函数的运行时间 def decrator(fun ...
- php指定长度 分割整形,php指定长度分割字符串str_split函数用法示例
本文实例讲述了php指定长度分割字符串str_split函数用法.分享给大家供大家参考,具体如下: 示例1:$str = 'abcdefgh'; $arr = str_split($str,2); 运 ...
- to_number用法示例_Number()函数以及JavaScript中的示例
to_number用法示例 Number()函数 (Number() function) Number() function is a predefined global function in Ja ...
- php解escape,PHP下escape解码函数用法示例
这篇文章主要为大家详细介绍了PHP下escape解码函数用法示例,具有一定的参考价值,可以用来参考一下. 感兴趣的小伙伴,下面一起跟随512笔记的小编小韵来看看吧!GB2312编码: 代码如下: fu ...
最新文章
- java追加文本到文件末尾
- php配置文件修改数据库上传,请问php.ini上传文件大小限制配置修改路径在哪里?是在数据库哪里吗?表头是?...
- pipreqs生成python项目依赖清单
- UVA10173(求凸包的面积最小外接矩形)
- 母子盗打电话竟为获取游戏Q币
- KVO-基本使用方法-底层原理探究-自定义KVO-对容器类的监听
- Vue之前端页面使用json编辑框
- 全阶滑模观测器程序_滑模观测器转子估算程序
- Apache和Nginx防盗链
- 数据和access数据的区别_Access处理数据
- 拆解百度自动驾驶最新动作:Apollo企业版和Apollo 3.5里的生意经和新风向 | CES 2019...
- mysql的主要指标_mysql 主要性能指标
- vue返回上一页面时回到原先滚动的位置
- win10下Java的JDK11下载与安装教程
- 盘点一下使用高德api踩得坑
- mysql执行存储过程报错1366_花花蘑菇
- [附源码]java毕业设计流浪宠物免费领养系统
- RocketMQ延迟消息的代码实战及原理分析
- 如何巧用微信生态搭建和运营私域流量
- 语言与区域设置ID (Language ID、Locales ID / LCID)