Home > Backend Development > PHP Tutorial > 运用PHP 进行简单正则替换

运用PHP 进行简单正则替换

WBOY
Release: 2016-06-13 11:11:29
Original
876 people have browsed it

使用PHP 进行简单正则替换
求一个简单的正则公式

code name="hello1" version="2012"<br />code name="123" version="2012"<br />code name="代码" version="2012"<br />
Copy after login


使用正则整替换成如下格式
code name="20121226-001" version="2012"<br />code name="20121226-002" version="2012"<br />code name="20121226-003" version="2012"<br />
Copy after login


------解决方案--------------------
$s=<<codes name="name1"
code name="hello1" version="2012"<br />code name="123" version="2012"<br />code name="代码" version="2012"<br />HTML;
$i=0;
echo preg_replace('/"(.+)"(?=\s+version)/em','"\""."20121226-00".++$i."\""',$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