1 比如
变成
2 比如
变成
3 比如
变成
结构说明
原结构必须是
求正则
自己写了一个 但不完美
$p = '/\$(\w+)=(\w+)/i' ;
$r = '$1="$2"' ;
$c = preg_replace($p, $r, $c);
无法匹配 Where=[FatherID]=0 部分 也无法判断是否在
能匹配上方三个例子的 给全部分
$Sql=select * from [{pre}Content] where [cid] in (3,4,5)
这个没有分界符号,不能判断,最后加个分号吧
<?php$s = '<qlist:m listname="m" $Row=10 $table=Channel $Where=[FatherID]=0 >$table=Channel<qlist:aa listname="aa" $Row=10 $Sql=select * from [{pre}Content] where [cid] in (3,4,5); $Type=Images>$Row=10<qlist:bb listname="bb" $Row=10> $table=Channel ';echo preg_replace( array('/(<.*)\$(Row=)(\d+)(.*>)/', '/(<.*)\$(table=)(\w+)(.*>)/','/(<.*)\$(Where=)(\[\w+\]=)(\d+)(.*>)/','/(<.*)\$(Type=)(\w+)(.*>)/', '/(<.*)\$(Sql=)(.*;)(.*>)/'), array('$1$2"$3"$4', '$1$2"$3"$4', '$1$2"$3$4"$5', '$1$2"$3"$4', '$1$2"$3"$4'), $s);?>
$Sql=select * from [{pre}Content] where [cid] in (3,4,5)
这个没有分界符号,不能判断,最后加个分号吧
<?php$s = '<qlist:m listname="m" $Row=10 $table=Channel $Where=[FatherID]=0 >$table=Channel<qlist:aa listname="aa" $Row=10 $Sql=select * from [{pre}Content] where [cid] in (3,4,5); $Type=Images>$Row=10<qlist:bb listname="bb" $Row=10> $table=Channel ';echo preg_replace( array('/(<.*)\$(Row=)(\d+)(.*>)/', '/(<.*)\$(table=)(\w+)(.*>)/','/(<.*)\$(Where=)(\[\w+\]=)(\d+)(.*>)/','/(<.*)\$(Type=)(\w+)(.*>)/', '/(<.*)\$(Sql=)(.*;)(.*>)/'), array('$1$2"$3"$4', '$1$2"$3"$4', '$1$2"$3$4"$5', '$1$2"$3"$4', '$1$2"$3"$4'), $s);?> 你要保证最后有个$才行,思路你都想出了,用我的改改也不难。
加油。
其实是$sql那个因为没有结尾符号判断,所以才需要加分号,其他其实已经实现功能了。
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号