php替换自定义标签内容,自定义标签替换函数(php)

自定义标签替换函数示例

function custom_markup_translate($str){

//array with regular expressions that match custom tags

$search = array(

"#\{bold\}(.*?)\{/bold\}#is",

"#\{italic\}(.*?)\{/italic\}#is",

"#\{underline\}(.*?)\{/underline\}#is",

"#\{heading\}(.*?)\{/heading\}#is",

"#\{subheading\}(.*?)\{/subheading\}#is",

"#\{link:(.*?)\}(.*?)\{/link\}#is",

"#\{elink:(.*?)\}(.*?)\{/elink\}#is",

"#\{unordered-list\}(.*?)\{/unordered-list\}\s*#is",

"#\{ordered-list\}(.*?)\{/ordered-list\}\s*#is",

"#\\s*\{list-element}(.*?)\{/list-element\}\s*#is",

"#\{picture:(.*?)\}#is",

"#\t#is",

"#\{comment}(.*?)\{/comment\}#is"

);

//array with HTML replacements

$replace = array(

'\\1',

'\\1',

'\\1',

'

\\1

',

'

\\1

',

'\\2',

'\\2',

'

  • \\1
',

'

  1. \\1
',

'

\\1',

'%5C%5C1',

'',

''

);

//perform the replacement

$step_1 = preg_replace($search, $replace, $str);

$step_2 = preg_split('#(\{HTML\}.*?\{HTML\})#is', $step_1, -1, PREG_SPLIT_DELIM_CAPTURE);

$return = '';

foreach($step_2 as $s2){

if(preg_match('#\{HTML\}#', $s2)){

$return .= preg_replace('#\{/?HTML\}#is', '', $s2);

}else{

$return .= nl2br($s2);

}

}

//return HTML markup

return $return;

}

?>

测试文本

{HEADING}Using a Custom Markup Language to Generate Optimized HTMl{/HEADING}

As we mentioned earlier, using a WYSIWYG editor frequently presents a problem

with regard to on-page optimization. Frequently, the editors do bot generate HTML

that uses tags that adequately delineate the stauctural meaning of elements in a

page. Since heading tags, such as h1, ul, and strong are indicators of the structure

within adocument, not using them will probably {BOLD}{ITALIC}decrease{/ITALIC}{/BOLD}

the rankings of a page, especially when a search engine is relying on on-page factors.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值