How to convert eregi to preg_match?

前端 未结 3 475
花落未央
花落未央 2021-01-05 04:26

I am using a lib which uses

eregi($match=\"^http/[0-9]+\\\\.[0-9]+[ \\t]+([0-9]+)[ \\t]*(.*)\\$\",$line,$matches)

but as eregi is deprecat

3条回答
  •  心在旅途
    2021-01-05 05:06

    You can try:

    preg_match("@^http/[0-9]+\\.[0-9]+[ \t]+([0-9]+)[ \t]*(.*)\$@i",$line,$matches)
    
    • You can drop the the $match=
    • You are using / as the delimiter and there is another / present in the regex after http, which effectively marks the end of your regex. When PHP sees the [ after this it complains.
    • You can use a different set of delimiters as @ or escape the / after http

提交回复
热议问题