<?php $str = 'http://127.0.0.1/c/1.php?ft=x7cjhttp://127.0.0.1/c/1.php?form=post&ft=gy4ehttp://127.0.0.1/c/1.php?ft=7yd4r&form=post';$str = preg_replace('/[\?&]ft=\w+/','',$str);var_dump($str);?><br><font color="#e78608">------解决方案--------------------</font><br> $arr=array('http://127.0.0.1/c/1.php?ft=x7cj','http://127.0.0.1/c/1.php?form=post&ft=gy4e','http://127.0.0.1/c/1.php?ft=7yd4r&form=post');print_r(array_map('foo',$arr));function foo($url){ $ar=parse_url($url); if(!isset($ar['query'])) return $url; parse_str($ar['query'],$arr); unset($arr['ft']); return $ar['scheme'].'://'.$ar['host'].$ar['path'].($arr ? '?'.http_build_query($arr) : '');}<br><font color="#e78608">------解决方案--------------------</font><br>这样写(注释掉后面的$s可测试前面的)<br>$s = 'http://127.0.0.1/c/1.php?seed=add&ft=7yd4r&form=post';<br>$s = 'http://127.0.0.1/c/1.php?ft=x7cj';<br>$s = 'http://127.0.0.1/c/1.php?form=post&ft=gy4e';<br>$s = 'http://127.0.0.1/c/1.php?ft=7yd4r&form=post';<br><br><strong>echo preg_replace('/([?&])ft=[^&]+(&?)/e', '"$2"==""?"":"$1"', $s);</strong><br><br>人家给你弄个数组,只不过是让你测试起来方便些<div class="clear"></div>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号