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

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

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.