I understand the title is vague, but I need help with this issue. I just can't seem to wrap my head around it.
Basically, I have a textarea where users insert their string/text like this:
Blah blah blah blah blah this is random text whatever it could be blah blah
* Un-ordered list item
* Un-ordered list item
Blah blah blah and here is some more random text because blah blah blah
* Un-ordered list item
* Un-ordered list item
As you can see, users can create a list by adding a * character that a PHP script just modify to generate the appropriate list tags.
What I have so far is this:
$text = array();
$c = 0;
foreach($lines as $line) {
if(strpos($line, "*") !== FALSE) {
if($c == 0) {
$text[] = "<ul>";
}
$text[] = "<li>" . trim(str_replace(array("*", "\n"), '', $line)) . "</li>";
$c++;
} else {
$c = 0;
$text[] = $line;
}
}
Which would return something like this:
Array
(
[0] => Blah blah blah blah blah this is random text whatever it could be blah blah
[1] =>
[2] => <ul>
[3] => <li>Un-ordered list item</li>
[4] => <li>Un-ordered list item</li>
[5] =>
[6] => Blah blah blah and here is some more random text because blah blah blah
[7] =>
[8] => <ul>
[9] => <li>Un-ordered list item</li>
[10] => <li>Un-ordered list item</li>
)
What I need is to be able to close that <ul> tag off after the list is done. As you can see, the user can add as many lists as they desire, so the code block needs to be flexible to accommodate that.
Here's an example of it in action: Example