foochuck Posted July 23, 2008 Share Posted July 23, 2008 I'm using the explode function... $pizza = "piece1,piece2,piece3,piece4,piece5,piece6"; $pieces = explode(",", $pizza); echo $pieces[0]; // piece1 I would like to include an actual comma "," in the pizza variable and have it appear in the string. For example I want: "piece,1,piece,2,piece,3,piece,4,piece,5,piece,6"; This isn't the real working sample. Anyway, my main question is how do I escape the actual commas so they are kept in the strings and distinguished from the delimiter commas??? Thanks FOO Link to comment https://forums.phpfreaks.com/topic/116273-comma-delimiter-question/ Share on other sites More sharing options...
DarkWater Posted July 23, 2008 Share Posted July 23, 2008 Put a \ before them and then use: split('[^\],', $pizza); Link to comment https://forums.phpfreaks.com/topic/116273-comma-delimiter-question/#findComment-597861 Share on other sites More sharing options...
foochuck Posted July 23, 2008 Author Share Posted July 23, 2008 The code I'm using already has $data = explode(",", trim($item['data'])); throughout... I don't want to break the code using split... Link to comment https://forums.phpfreaks.com/topic/116273-comma-delimiter-question/#findComment-597864 Share on other sites More sharing options...
DarkWater Posted July 23, 2008 Share Posted July 23, 2008 Just switch all the explode()'s to split(). It's the only way to do it in this case because you need regular expressions. Link to comment https://forums.phpfreaks.com/topic/116273-comma-delimiter-question/#findComment-597865 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.