目录
描述
译文
将文本中的表情符号转换为表情图像。
只在选项'use_smilies'为true,且函数中的全局变量不为空时转换表情符号。
原文
如 :-)、:-P 等文本表 符号为图像
有 'use_smilies'
选项被设置为 true
并且函数中的全局变量 为空的时候才转换
用法
<?php convert_smilies( $text ) ?>
参数
返回值
示例
1 2 3 4 5 |
/* ---------------------------------- * wordpress之魂 © http://wphun.com * ---------------------------------- */ echo convert_smilies("This smiley is going to show as an image... :) "); |
注意
历史
添加于 版本: 0.71
源文件
convert_smilies() 函数的代码位于 wp-includes/formatting.php
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
/* ---------------------------------- * wordpress之魂 © http://wphun.com * ---------------------------------- */ /** * Convert text equivalent of smilies to images. * * Will only convert smilies if the option 'use_smilies' is true and the global * used in the function isn't empty. * * @since 0.71 * * @global string|array $wp_smiliessearch * * @param string $text Content to convert smilies from text. * @return string Converted content with text smilies replaced with images. */ function convert_smilies( $text ) { global $wp_smiliessearch; $output = ''; if ( get_option( 'use_smilies' ) && ! empty( $wp_smiliessearch ) ) { // HTML loop taken from texturize function, could possible be consolidated $textarr = preg_split( '/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // capture the tags as well as in between $stop = count( $textarr );// loop stuff // Ignore proessing of specific tags $tags_to_ignore = 'code|pre|style|script|textarea'; $ignore_block_element = ''; for ( $i = 0; $i < $stop;="" $i++="" )="" {="" $content="$textarr[$i];" if="" we're="" in="" an="" ignore="" block,="" wait="" until="" we="" find="" its="" closing="" tag="" if="" (="" ''="=" $ignore_block_element="" &&="" preg_match(=""><(' .="" $tags_to_ignore="" .="" ')="">/', $content, $matches ) ) { $ignore_block_element = $matches[1]; } // If it's not a tag and not in ignore block if ( '' == $ignore_block_element && strlen( $content ) > 0 && '<' !="$content[0]" )="" {="" $content="preg_replace_callback(" $wp_smiliessearch,="" 'translate_smiley',="" $content="" );="" }="" did="" we="" exit="" ignore="" block="" if="" (="" ''="" !="$ignore_block_element" &&=""></'>' == $content ) { $ignore_block_element = ''; } $output .= $content; } } else { // return default text. $output = $text; } return $output; } </('></.*> |
- 原文:http://codex.wordpress.org/Function_Reference/convert_smilies
- 翻译:黄聪@WordPress之魂