Boxerman Posted August 22, 2017 Share Posted August 22, 2017 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 Quote Link to comment Share on other sites More sharing options...
Boxerman Posted August 22, 2017 Author Share Posted August 22, 2017 Whoops, got that fixed: for people in the future: $genres = explode(",",$genre); foreach($genres as $value){ echo $value . ", "; } My question for people, how do i remove the comma from the last one? Quote Link to comment Share on other sites More sharing options...
ginerjm Posted August 22, 2017 Share Posted August 22, 2017 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! Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted August 22, 2017 Share Posted August 22, 2017 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. Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted August 22, 2017 Share Posted August 22, 2017 If you're still trying to download copyrighted material, you better do that elsewhere. This will not be tolerated in any shape or form. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.