钩子文档

wp_spaces_regexp

💡 云策文档标注

概述

wp_spaces_regexp 是一个 WordPress 过滤器,用于修改匹配常见空白字符的正则表达式模式。它允许开发者根据网站的语言或编码需求自定义空白字符的匹配规则。

关键要点

  • 过滤器名称:wp_spaces_regexp
  • 用途:过滤常见空白字符的正则表达式,适用于非英语网站或非 UTF-8 编码的场景
  • 参数:$spaces,一个字符串,表示匹配常见空白字符的正则模式
  • 默认值:'[rnt ]|xC2xA0| ',匹配回车、换行、制表符、空格、UTF-8 空格和 HTML 实体空格
  • 引入版本:4.0.0

代码示例

$spaces = apply_filters( 'wp_spaces_regexp', '[rnt ]|xC2xA0| ' );

注意事项

对于非英语网站,空白字符可能不同;对于非 UTF-8 编码网站,0xC2 0xA0 序列可能不适用,需通过此过滤器调整正则表达式。


📄 原文内容

Filters the regexp for common whitespace characters.

Description

This string is substituted for the s sequence as needed in regular expressions. For websites not written in English, different characters may represent whitespace. For websites not encoded in UTF-8, the 0xC2 0xA0 sequence may not be in use.

Parameters

$spacesstring
Regexp pattern for matching common whitespace characters.

Source

$spaces = apply_filters( 'wp_spaces_regexp', '[rnt ]|xC2xA0| ' );

Changelog

Version Description
4.0.0 Introduced.