bbcode unparser regex help

前端 未结 3 410
礼貌的吻别
礼貌的吻别 2021-01-06 23:56

I have this function to parse bbcode -> html:

  $this->text = preg_replace(array(
    \'/\\[b\\](.*?)\\[\\/b\\]/ms\', 
    \'/\\[i\\](.*?)\\[\\/i\\]/ms\',         


        
3条回答
  •  鱼传尺愫
    2021-01-07 00:11

    It's pretty safe to say it's nigh impossible to build a reliable way to convert html to bbcode with just a slew of regexes. Use a parser (DOMDocument for instance), remove invalid elements & attributes with xpath's & inspection and then recursively walk it creating a bbcode string on the way (or just ignore invalid tags / attributes on the way).

提交回复
热议问题