Array implode to MySql and then retrieve values and explode back to same array not working if commas already existed in string

Tiago Sa :

If I implode an array $arr = ["Hello my, name is Steve", "How are you?"] to string to insert to MySQL database like so: $data = implode(',',$arr);, when I try to retrieve those values and explode it back into array: $arr2 = explode(',',$data); it returns : ["Hello my", "name is Steve", "How are you?"]

How do I get it to ignore the comma thats already in between quotes and explode as:

["Hello my, name is Steve", "How are you?"]

Omi in a hellcat :

Instead you can use json_encode and json_decode.

Try this out:

$arr = ["Hello my, name is Steve", "How are you?"]
$data = json_encode($arr); //Insert $data into mysql 
//Then to retrieve values 
$arr2 = json_decode($data); //returns ["Hello my, name is Steve", "How are you?"]

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=174333&siteId=1