Archimedees Posted October 9, 2007 Share Posted October 9, 2007 Hi guys, I have a problem, don't most of us here? I have a string with spaces, I want to replace the spaces with commas and then explode the string and create an array. How do I go about this? Please assist me. For example the string might look like this. "weird weirdo quiteweird nuts crazy mad verycrazy banana bonkers" Link to comment https://forums.phpfreaks.com/topic/72463-solved-str_replace/ Share on other sites More sharing options...
MadTechie Posted October 9, 2007 Share Posted October 9, 2007 <?php $data = "weird weirdo quiteweird nuts crazy mad verycrazy banana bonkers"; $data = str_replace(" ", ",", $data); $NewData = explode(",", $data ); ?> OR JUST, explode with a space delimiter <?php $data = "weird weirdo quiteweird nuts crazy mad verycrazy banana bonkers"; $NewData= explode(" ", $data ); ?> Link to comment https://forums.phpfreaks.com/topic/72463-solved-str_replace/#findComment-365383 Share on other sites More sharing options...
MmmVomit Posted October 9, 2007 Share Posted October 9, 2007 You can use explode as is. explode(' ', $your_string); Link to comment https://forums.phpfreaks.com/topic/72463-solved-str_replace/#findComment-365384 Share on other sites More sharing options...
Archimedees Posted October 9, 2007 Author Share Posted October 9, 2007 I could hug the world for a moment. Thanks mates! Link to comment https://forums.phpfreaks.com/topic/72463-solved-str_replace/#findComment-365388 Share on other sites More sharing options...
MadTechie Posted October 9, 2007 Share Posted October 9, 2007 can you click solved please:) Link to comment https://forums.phpfreaks.com/topic/72463-solved-str_replace/#findComment-365393 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.