I have a field of text where users can write specific command to get some html.
For example:
Text Text Text Text
[*] first entry
[*] second entry
[*] 3rd...
Text Text
This text should be converted with regex to something like this:
text text
<ol>
<li>FirstEntry</li>
<li>Second</li>
..
</ol>
text text
Any suggestion?
The regex that matches the line with entry is something like this:
/\[\*\].+/i
The problem is how to insert correctly the <ol>
and </ol>
My solution
I was thinking I could parse all line of text and when the parser encouter the first line that starts with [*] then put an <ol>
Same thing for the </ol>
Until now I have made the script that converst single [*] ...
to <li> ...
preg_replace('/\[\*\](.+)/i','<li>$1</li>',$str);
I need the <ol>
part
and
– Nov 10 '12 at 15:00part