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条)

报告相同问题?

悬赏问题

  • ¥20 安装 opencv4nodejs 报错
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择
  • ¥15 部分网页页面无法显示!