Jump to content

Comma separated list converted to ordered list...


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. 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.