dongyuanguang3893 2011-09-08 06:15
浏览 73
已采纳

preg_replace和正则表达式帮助

A friend helped us with this line of code a while back, and I'm trying to get it to work for this:

$curPageUrl = "http://www.site.com/index.php?sort=a";
$currentPage = preg_replace("/&sort=\w+/", "", $curPageUrl);
echo $currentPage; // http://www.site.com/index.php?sort=f?sort=a?sort=z

For example, $curPageUrl gets the clients page they are on and then it passes it through this.

Basically, we want $currentPage to strip off:

?sort=a
?sort=f
?sort=z

from the $curPageUrl

I hope my example helped.

Thank you.

  • 写回答

3条回答 默认 最新

  • duanbixia7738 2011-09-08 06:21
    关注
    preg_replace("/(\?|\&)sort=\w+/", "", $curPageUrl);
    

    It will accept '&' or '?'.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 求指导ADS低噪放设计
  • ¥15 CARSIM前车变道设置
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存