Jump to content

Comma separated list converted to ordered list...


Jim R

Recommended Posts

Is there a way to take data that is listed like a,b,c,d,e and turn that into an unordered list?

 

Basically, I'm going to have a list of schools that will be listed with comma separators.  I'll print that data out in two places, one will be printed as it's in the database.  The other I would like to echo as an unordered list.

 

 

A quick and dirty way would be to use str_replace on the commas. This would fail if any of the values intentionally contained commas, though.

$list = 'a,b,c,d,e';
echo "<ol>\n<li>\n";
echo str_replace(',', "</li>\n<li>", $list);
echo "\n</li>\n</ol>\n";

is the format always the same?

 

For where I would use it, the format would always be the same.  It would be progressive, 2011, 2012, 2013, etc.  I would Get the slug, such as commitment-2013, hopefully extract the 2013 part and use it to query another table.

 

Pikachu2000,

 

I'm getting this error:

 

Warning: Wrong parameter count for str_replace() in /home/jwrbloom/public_html/resources/wp-playerProfile.php on line 62

 

Using this code:

echo '<ul>List:
	<li>';

echo str_replace(',','</li>\n<li>' . $line['committed']);

echo '\n</li>\n</ul>\n';	

Still getting the error. 

 

Warning: Wrong parameter count for str_replace() in /home/jwrbloom/public_html/resources/wp-playerProfile.php on line 62

 

Here is the code with the double quotes:

 

	echo '<ul>List:
	<li>';	

62 -->      echo str_replace(",","</li>\n<li>" . $line['committed']);

	echo "\n</li>\n</ul>\n";	

I "JUST" did that before the notification of your post came through.  :)

 

I had that as an issue on something else a year ago, and it took about three days to get it figure out.  It works.  Thank you.

 

I'm definitely keeping this topic handy, as I like the exploding idea too for another project. 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.