preg_replace() [function.preg-replace]: Unknown modifier '/' in /home/

前端 未结 2 1896
逝去的感伤
逝去的感伤 2021-01-28 16:10

in my website i want to replace links with some other link like this

www.abc.com or http://abc.com will be replaced with

http:/

相关标签:
2条回答
  • 2021-01-28 16:24
    "/\[url]www|http://.([^'\"]*)\[\/url]/iU",
     ^               ^^                  ^
    

    You either need to escape the two // in the middle to \/\/, or, better, use different delimiters for the regex:

    "~\[url]www|http://.([^'\"]*)\[/url]~iU",
    
    0 讨论(0)
  • 2021-01-28 16:48

    There is few ways to solve that

    Escaping "/"

    $search_array = array(
      "/\[url]www|http:\/\/.([^'\"]*)\[\/url]/iU",
      "/\[url]([^'\"]*)\[\/url]/iU",
      "/\[url=www|http:\/\/.([^'\"\s]*)](.*)\[\/url]/iU",
      "/\[url=([^'\"\s]*)](.*)\[\/url]/iU"
    );
    

    Or using different regexp seperator like "#"

    $search_array = array(
      "#\[url]www|http://.([^'\"]*)\[\/url]#iU",
      "#\[url]([^'\"]*)\[\/url]#iU",
      "#\[url=www|http://.([^'\"\s]*)](.*)\[\/url]#iU",
      "#\[url=([^'\"\s]*)](.*)\[\/url]#iU"
    );
    
    0 讨论(0)
提交回复
热议问题