calling function inside preg_replace thats inside a function

后端 未结 2 383
悲&欢浪女
悲&欢浪女 2020-11-29 12:29

I have some code with the a structure similar to this

           function bbcode($Text)
           { //$Text = preg_replace(\"/\\[video\\](.+?)\\[\\/video\\]         


        
相关标签:
2条回答
  • 2020-11-29 12:30

    try preg_replace_callback

    return preg_replace_callback("/\[video\](.+?)\[\/video\]/", 'embed_video', $Text);
    
    function embed_video($matches)
    {
      return $matches[1] . 'foo';      
    }
    
    0 讨论(0)
  • 2020-11-29 12:56

    You can use the "e" modifier on preg_replace() (see Pattern Modifiers)

    return preg_replace("/\[video\](.+?)\[\/video\]/e", "embed_video('$1')", $Text);
    

    which tells preg_replace() to treat the second parameter as PHP code.

    0 讨论(0)
提交回复
热议问题