Home >Backend Development >PHP Tutorial >Php正则替换的一个守则

Php正则替换的一个守则

WBOY
WBOYOriginal
2016-06-13 12:08:34818browse

Php正则替换的一个规则
有一段文字,下划线 字符可能有多有少,每一个字符都移动到 标签里面来,比如:

 已知集合,则 __ _____。
希望替换成:
已知集合,则         

请教一下如何实现。

------解决思路----------------------

$s = "__<u> </u>_____";<br />echo preg_replace('#(_*)(<u>[^<]*)(</u>)(_*)#e', '"$2".str_repeat(" ", strlen("$1")+strlen("$4"))."$3"', $s); 
        

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn