I’m having some trouble with Converting Text to a list. The situation is that I get text like the following from the database:
"Hello, my name is michael, my hobbys are:
- computers
- guitar
and some more blabla "
No I want to transform the listed points(computers&guitar in this case) into an unordered html list, so the resulst should look like this:
"Hello, my name is michael, my hobbys are:
<ul>
<li>computers<li>
<li>guitar</li>
</ul>
and some more blabla ".
I think that the best solution would be doing this by regex, but my knowledge there isnt good enough to realise this. I tried it by replacing all /\n- / width a <li> tag, which worked. But how do I get the closing </li>, and even more confusing for me, how do I get the both <ul> tags?
Thank you in advance for any advice.
Your syntax looks almost identical to Markdown, a simple markup language. The only difference is a little bit of whitespace:
It’s converted to this:
There are a few PHP Markdown projects that I think you’ll find useful.