christa Posted October 14, 2009 Share Posted October 14, 2009 Hi all i have some names (imploded by comma): toronto,paris,madrid Now, i would obtain this result: 'toronto','paris','madrid' How can i do? thanks Link to comment https://forums.phpfreaks.com/topic/177689-split-string/ Share on other sites More sharing options...
johnsmith153 Posted October 14, 2009 Share Posted October 14, 2009 $a = "toronto,paris,madrid"; $array = explode(",",$a); will get your 3 values stored in an array named $array so: echo $array[0]; will display: toronto As for the next bit, I'm not sure what you're asking. Link to comment https://forums.phpfreaks.com/topic/177689-split-string/#findComment-936918 Share on other sites More sharing options...
simshaun Posted October 14, 2009 Share Posted October 14, 2009 Explode the string into an array and loop through it, modifying the values so that they are wrapped with single quotes. Link to comment https://forums.phpfreaks.com/topic/177689-split-string/#findComment-936921 Share on other sites More sharing options...
johnsmith153 Posted October 14, 2009 Share Posted October 14, 2009 $a = "toronto,paris,madrid"; $array = explode(",",$a); $newVal = ""; foreach ($array as $a) { if($newVal!="") { $newVal .= ","; } $newVal .= "'".$a."'"; } echo $newVal; Link to comment https://forums.phpfreaks.com/topic/177689-split-string/#findComment-936923 Share on other sites More sharing options...
christa Posted October 14, 2009 Author Share Posted October 14, 2009 ok, thanks a lot! Link to comment https://forums.phpfreaks.com/topic/177689-split-string/#findComment-936926 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.