Regex to replace 'li' with 'option' without losing class and id attributes

Posted by Earthman Web on Stack Overflow See other posts from Stack Overflow or by Earthman Web
Published on 2010-05-06T21:52:17Z Indexed on 2010/05/06 21:58 UTC
Read the original article Hit count: 224

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about php

Related posts about preg-replace