views:

75

answers:

3

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?

+2  A: 

Like this:

echo str_replace('</li', '</option', (str_replace('<li', '<option', $string));
SLaks
+6  A: 

I think a simple string replacement would be best

str_replace('<li', '<option', $string)

Same for ending tags

str_replace('</li', '</option', $string)
Syntax Error
*Sigh* Community wiki, why must you deny me my sweet, sweet reputation points?
Syntax Error
@Syntax Error - Clearly, the whole world is against you. :)
ChaosPandion
A: 

You need a delimiter in the pattern. For example:

$pattern = '@<li @';
$replacement = '<option ';
Johan