Home > Backend Development > PHP Tutorial > 觅高手来求一段正则替换的代码

觅高手来求一段正则替换的代码

WBOY
Release: 2016-06-13 12:13:30
Original
850 people have browsed it

找高手来求一段正则替换的代码
求一段替换算法。
原文举例:
如:
文字文字中间有个长下划        空白,又有一个短下划     了,或者这里是第三个     下划。

希望替换成:
文字文字中间有个长下划空白,又有一个短下划了,或者这里是第三个下划。

下划区域有可能只有一个,或者更多,上面例子用的是三个。
------解决思路----------------------

$s = '文字文字中间有个长下划<u>        </u>空白,又有一个短下划<u>     </u>了,或者这里是第三个<u>     </u>下划。';<br />$i = 0;<br />echo preg_replace('/<u>.+?<\/u>/se', '"<span id=\"u" . ++$i . "\"></span>"', $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