Regex to replace 'li' with 'option' without losing class and id attributes
- by Earthman Web
I am looking for a solution using preg_replace or similar method to change:
<li id="id1" class="authorlist" />
<li id="id2" class="authorlist" />
<li id="id3" class="authorlist" />
to
<option id="id1" class="authorlist" />
<option id="id2" class="authorlist" />
<option id="id3" class="authorlist" />
I think I have the pattern correct, but not sure how to do the replacement part...
Here is the (wordpress) php code:
$string = wp_list_authors( $args ); //returns list as noted above
$pattern = '<li ([^>]*)';
$replacement = '?????';
echo preg_replace($pattern, $replacement, $string);
Suggestions, please?