WordPress函数文档balanceTags()
平衡补齐标签 描述 译文 函数仅在被要求以及选项被设为校正标签时会对标签进行自动校正。 只要对标签进行校正,就…
平衡补齐标签
描述
译文
函数仅在被要求以及选项被设为校正标签时会对标签进行自动校正。
只要对标签进行校正,就会用到’use_balanceTags’选项。在校正标签前,$force参数和 ‘use_balanceTags’选项值都必须为true。
原文
根据 forced 参数或者 use_balanceTags 选项平衡补齐标签。
‘use_balanceTags’ 选项或者 $forced 参数任何一个设置为 true,该函数就会补齐文本的标签。
调用 force_balance_tags() 进行补全。
用法
<?php balanceTags( $text, $force ); ?>
参数
$text
(string) (必填) 将补齐标签的文本
默认值: None
$force
(boolean) (可选) 如果该参数为 true,则忽略use_balanceTags option 中的值。
默认值: false
返回值
(string)
补齐之后的标签
示例
不完整的LI标签:
| 
 1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
 | 
 /* ———————————- 
 * wordpress函数 kim收集 
 * ———————————- */ 
<?php 
$html = ‘<ul>
 
  <li>this 
  <li>is 
  <li>a 
  <li>list 
</ul>’;
 
echo balanceTags($html, true);
 
?> 
 | 
输出的 HTML:
| 
 1 
2 
3 
4 
5 
6 
7 
8 
9 
 | 
 /* ———————————- 
 * wordpress函数 kim收集 
 * ———————————- */ 
<ul>
 
  <li>this
 
  </li><li>is
 
  </li><li>a
 
  </li><li>list
 
</li></ul>
 
 | 
注意
历史
添加于 版本: 0.71
源文件
balanceTags() 函数的代码位于 wp-includes/formatting.php.
| 
 1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
 | 
 /* ———————————- 
 * wordpress函数 kim收集 
 * ———————————- */ 
/** 
 * Balances tags if forced to, or if the ‘use_balanceTags’ option is set to true. 
 * 
 * @since 0.71 
 * 
 * @param string $text  Text to be balanced 
 * @param bool   $force If true, forces balancing, ignoring the value of the option. Default false. 
 * @return string Balanced text 
 */ 
function balanceTags( $text, $force = false ) {
 
	if ( $force || get_option(‘use_balanceTags’) == 1 ) {
 
		return force_balance_tags( $text );
 
	} else {
 
		return $text;
 
	}
 
} 
 | 
- 原文:http://codex.wordpress.org/Function_Reference/balanceTags
 
类别:WordPress函数文档、 
		本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。

评论功能已经关闭!