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

Php正则替换的一个规则

WBOY
Release: 2016-06-23 13:47:16
Original
864 people have browsed it

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

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

请教一下如何实现。


回复讨论(解决方案)

str_replace去掉u标签,然后左右两边再加上

你要考虑到,可能存在这种情况阿:

如果(______)。已知集合,则 __ _____。

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

谢谢版主,目标实现了。

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template