Home > Backend Development > PHP Tutorial > 求一个正则 $Row=10 转 Row="10"

求一个正则 $Row=10 转 Row="10"

WBOY
Release: 2016-06-23 13:28:34
Original
760 people have browsed it



变成



或 


变成



或 


变成




三处必须:

qlist:后边的 m或m2 是可能会变的 这里要保持替换前后一致
listname="xxx" 就是上方冒号后的内容 必须存在
中间的其他部分 是多种多样的 需要把格式  $aaa=bbb 全转成 aaa="bbb" 格式 有就转 没有就算 允许不填 


回复讨论(解决方案)

$s = '<qlist:m  $Row=10 $table=Channel $Where=[FatherID]=0 ><qlist:m2  $Row=10   ><qlist:m3>';echo preg_replace(  array('/<qlist:(\w+)/', '/(\$Row=)(\d+)/'),  array('$0 listname="$1"', '$1"$2"'),  $s);
Copy after login
Copy after login
<qlist:m listname="m"  $Row="10" $table=Channel $Where=[FatherID]=0 ><qlist:m2 listname="m2"  $Row="10"   ><qlist:m3 listname="m3">
Copy after login
Copy after login

$s = '<qlist:m  $Row=10 $table=Channel $Where=[FatherID]=0 ><qlist:m2  $Row=10   ><qlist:m3>';echo preg_replace(  array('/<qlist:(\w+)/', '/(\$Row=)(\d+)/'),  array('$0 listname="$1"', '$1"$2"'),  $s);
Copy after login
Copy after login
<qlist:m listname="m"  $Row="10" $table=Channel $Where=[FatherID]=0 ><qlist:m2 listname="m2"  $Row="10"   ><qlist:m3 listname="m3">
Copy after login
Copy after login




$table=Channel $Where=[FatherID]=0

这部分没有加上 双引号呢 得这样 麻烦大神再看看 谢谢

<?php$s = '<qlist:m  $Row=10 $table=Channel $Where=[FatherID]=0 ><qlist:m2  $Row=10   ><qlist:m3>'; echo preg_replace(  array('/<qlist:(\w+)/', '/\$(Row=)(\d+)/', '/\$(table=)(\w+)/','/\$(Where=)(\[(\w+)\]=)(\d+)/'),  array('$0 listname="$1"', '$1"$2"', '$1"$2"', '$1"$2$4"'),  $s);?>
Copy after login





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