Doesn't work preg_replace_callback



  • We need to transform the BB-tag. [hide_guest][/hide_guest]I do, but it's always like,

    $parsered = 'Текст [hide_guest]Скрыто[/hide_guest] Текст';
    

    $text = preg_replace_callback('#[hide_guest](.+?)[/hide_guest]#si', 'hide_guest', $parsered);

    function hide_guest($match)
    {
    return '<div class="spoiler">'.$match[1].'</div>';
    }

    echo $text;



  • What does str_replace not suit you? It'll work much faster. That's how it works correctly:

    $text = str_replace('[hide_guest]', '<div class="spoiler">', $parsered);
    

    $text = str_replace('[/hide_guest]', '</div>', $text);

    It works faster than regular expression


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2