【问题标题】:Regex, need support正则表达式,需要支持
【发布时间】:2012-07-02 10:00:22
【问题描述】:

我有链接:

/admin/index.php
/admin/index.php?do=delete_user
/forum/index.php?search=aaa&type=a
/index.php
/index.php?p=home

等等……

如何 preg_replace() 链接只有 index.php 没有 GET 会改变(如果有 GET 不'replace)。

谢谢,它工作正常,但为什么不能工作这个 (?!&)、(?!\&)?如果在 asd.aa/index.php?news=1 存在 & (asd.aa/index.php?news=1&dont=change) 之后,我想保持不变

【问题讨论】:

  • 我认为您需要澄清这一点,这样我们才能准确了解您想要什么。
  • 您的问题不清楚,请添加示例输入输出。
  • 请更改您的标题以更具描述性
  • GET 是什么意思?可能是查询字符串参数,或者实际上是 http get 请求?
  • 让我试着把它弄好。你想把所有没有GET参数的链接都替换掉,只用index.php去掉index.php,但是如果有GET参数就不管了?

标签: php regex preg-replace


【解决方案1】:

使用否定前瞻:'/index\.php(?!\?)/' 将仅在 index.php 之后没有 ? 时匹配

【讨论】:

    猜你喜欢
    • 2011-04-23
    • 2011-01-05
    • 1970-01-01
    • 2014-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-17
    • 2012-11-12
    相关资源
    最近更新 更多