-
Regex question
I have recently been presented with a problem.
Lets take the list
[ul=list1,list2,list3]
I am trying to figure out how to extract that list and turn it into a HTML ul.
Though, I don't think regex will be able to do something like this, I could be wrong.
Anyone with an ideas of how I could do this?
Edit: This list will be embedded in a text file with lots of other text so the issue isn't how I can parse just that list by itself, but how can I parse that list when its mixed in with other text.
-
Re: Regex question
Yes, regular expressions should be able to help you here. You know that [ul= is a must-have in order to identify it as an unordered list.
This, for example, should be a good starting point.
\[ul=[a-zA-Z0-9,]*\]
I assume you then know how to parse the list to get the list items...
-
Re: Regex question
You could use the 'e' modifier to call a function which formats the list items.
PHP Code:
function listformat($listitems) { /* ... */ };
preg_replace('#\[ul=([^\],],?)+\]#es', "'<ul>'.listformat('\\1').'</ul>'", $subject);
Something along those lines.