[link]...[/link] BBcode parsing
Posted: Wed Jan 12, 2005 1:47 pm
Hi all,
I have the following:
// plain list
$patterns = array("/\[list\]/i", "/\[\*\]([^\[.]+)/i", "/\[\/list\]/i");
$replacements = array("<ul>", "<li>\\1</li>", "</ul>");
$string = preg_replace($patterns, $replacements, $string);
// fancy list
$patterns = array("/\[list=(a|A|i|I|1)\]/i", "/\[\*\]([^\[.]+)/i", "/\[\/list\]/i");
$replacements = array("<ol type=\"$1\">", "<li>$2</li>", "</ol>");
$string = preg_replace($patterns, $replacements, $string);
When I enter:
[list=A]
[*]1
[*]2
[/list]
The list is displayed correctly but, any text underneath the list is indented towards the right as if it were a list within the first list.
This seems to be because my HTML source code is:
<ol type="A">
<li>1
</li><li>2
</li></ul>
What should be a closing </ol> is a closing </ul>
If I reverse the parsing of plain lists and fancy lists in the code, I no longer get the text following indented, but my list is empty with the source code being:
<ol type="A">
<li></li><li></li></ol>
I'm at a loss - any help?
I have the following:
// plain list
$patterns = array("/\[list\]/i", "/\[\*\]([^\[.]+)/i", "/\[\/list\]/i");
$replacements = array("<ul>", "<li>\\1</li>", "</ul>");
$string = preg_replace($patterns, $replacements, $string);
// fancy list
$patterns = array("/\[list=(a|A|i|I|1)\]/i", "/\[\*\]([^\[.]+)/i", "/\[\/list\]/i");
$replacements = array("<ol type=\"$1\">", "<li>$2</li>", "</ol>");
$string = preg_replace($patterns, $replacements, $string);
When I enter:
[list=A]
[*]1
[*]2
[/list]
The list is displayed correctly but, any text underneath the list is indented towards the right as if it were a list within the first list.
This seems to be because my HTML source code is:
<ol type="A">
<li>1
</li><li>2
</li></ul>
What should be a closing </ol> is a closing </ul>
If I reverse the parsing of plain lists and fancy lists in the code, I no longer get the text following indented, but my list is empty with the source code being:
<ol type="A">
<li></li><li></li></ol>
I'm at a loss - any help?