Stackoverflow as a regular expression parser? _em_ * bold * in php

Hi, creating a parser in php as you can see below, it converts

*this* _this_to something like this this

$db['profile']['information'] = str_replace( "\n" , "<br/>" , $db['profile']['information']);
$db['profile']['information'] = preg_replace('/\*([^\*]+)\*/', '<strong>\1</strong>', $db['profile']['information']);
$db['profile']['information'] = preg_replace('/_([^[_]+)_/', '<em>\1</em>', $db['profile']['information']);
$db['profile']['information'] = preg_replace('/\[img\]((?:[^\[]+|\[(?!img\]))*)\[img\]/', '<img src="\1" />', $db['profile']['information']);

the problem is on img.

For example, I have a url [img]123_460217980773_23232_11_*23123*_n.jpg[img]and you know what it will parse. his epics. can anyone help me solve this problem?

and thanks for your time looking in

Adam Ramadhan

+3
source share
2 answers

Regular expressions, although useful in many situations, are definitely not the right tool for manually parsing structured text languages , and Markdown can be considered one of them.

, StackOverflow, Markdown, .

+7

, , , , , .

, , ( bbcode, , , , , )

http://en.wikipedia.org/wiki/Finite-state_machine

0

Source: https://habr.com/ru/post/1782101/


All Articles