Jump to content

Strip comma and put words into array


Boxerman

Recommended Posts

Hey all,

 

I'm trying to strip commas and put the single words into an array:

 

for example: output will be like: action, comedy, horror, war

 

What i need to do is strip the comma and add the single words into an array called genres.. is this possible?

 

I got the stripping done like so:

$genres = str_replace(',',' ',$genre);

but as you can see it only adds a space, i want to have them as single words so i can hyperlink them to different pages.

 

Any help in pointing me the right way would be amazing!

 

Thanks ALL

Link to comment
Share on other sites

Let's see.  First you have a comma-separated string of words.  Then you explode the words into an array.  Now you want to show the words again, each with a comma following them?

 

You were better off before you made this post!

Link to comment
Share on other sites

It's generally a good idea to give some context rather than pull the problem out of nowhere. Where is the data coming from?

 

Comma-separated values can be valid in some cases, but a lot of times, they're a very poor choice or even plain wrong (like when you store them in a database table). When you naively connect strings with no escaping and no quoting, you're also likely to run into trouble.

Link to comment
Share on other sites

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.