Issue
I am stuck with this. I tried json_decode but it gives me an error.
How can I remove the "[]"
and the ' " " '
characters of my string?
I have a string with this values ["Red Cat","Black Cat","Red Shoes"]
i want to remove and make my string like these: Red Cat, Black Cat, Red Shoes
Here i tried to make like this:
$data = json_decode($display_data);
and also i tried something that I've searched: $data = preg_replace('/[^a-zA-Z0-9_ %\[\]\.\(\)%&-]/s', ' ', $display_data);
Solution
From the comments: 'use json_decode'. Example:
$display_data = '["Red Cat","Black Cat","Red Shoes"]';
$data = json_decode($display_data); // Here we have array of strings
$result = implode(', ', $data); // Convert array back to one string
echo $result; // here we have "Red Cat, Black Cat, Red Shoes"
Answered By - Anton Answer Checked By - Senaida (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.