dongqian1925 2011-02-15 02:03
浏览 66

我可以在这里使用preg_match而不是弃用的eregi,如果是这样的话怎么样?

current code

eregi("(.*)/index.php$", $scriptName, $regs)

thinking along lines of

preg_match("(.*)/index.php$", $scriptName, $regs)

but not sure what the $regs bit is and also what I need to change in the brackets to make it work?

  • 写回答

2条回答 默认 最新

  • duanshan1977 2011-02-15 02:08
    关注
    preg_match_all("/(.*)\/index.php$/", $scriptName, $regs)
    

    Note you can use most characters as regex delimiters in PHP, e.g. ~.

    but not sure what the $regs bit is and also what i need to change in the brackets to make it work?

    $regs will be the matches. preg_match_all() has this behaviour, with the third argument. It is passed by reference, so you can simply start subscripting $regs if there were successful matches. [0] will have the entire match, and [1] will have the portion proceeding /index.php at the end of the string.

    As for changes in brackets, I've always called those parenthesis so I will assume that is what you meant (sorry for nitpicking). Are you referring to the arguments inside the function's parenthesis, or the matching group in the regex itself? Either way, just use the code above :)

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作