I'm creating a forum in which the user input text that he will be able to format using certain method. I've been able to accomplish most of the string work using substring() but I'm having trouble witht the Ordered List and Unordered list.
I'll take the unordered as an example.
The user input will be:
Example of text and here is my UL:
* Element 1
* Element 2
* Element 3
* Element 4
* Element 5
Thank you. Another one:
* Another 1
* Another 2
It will go in the Database like this and then I want to work this out in php to get the following output:
Example of text and here is my UL:
<ul>
<li>Element 1</li>
<li>Element 2</li>
<li>Element 3</li>
<li>Element 4</li>
<li>Element 5</li>
<ul>
Thank you. Another one:
<ul>
<li>Another 1</li>
<li>Another 2</li>
<ul>
The problem here is that i know how to replace the "*" for <li> but I can't figure out how to find the first 5 and then the 2 other one so they can both have their ul tags <ul></ul> around them.
I'm using bl2br() at the start of my function so the cariage are all
Here's a part of my function cutted down a bit to help:
function String_ToOutput($String_Output){
//Replace Cariage with HTML Code
$Temp_String = nl2br($String_Output);
//List Code
while(($pos = strpos($Temp_String, "\n*")) !== false){
$Temp_String = substr($Temp_String, 0, $pos) . "<ul><li>" . substr($Temp_String, $pos + 3);
$pos = strpos($Temp_String, "\n", $pos);
while((substr($Temp_String, $pos+1, 1)) == "*"){
$Next = strpos($Temp_String, "\n", $pos);
$Temp_String = substr($Temp_String, 0, $pos) . "<li>" . substr($Temp_String, $pos + 2);
$pos = $Next;
}
}
return $Temp_String;
}
Thanks for your help