Genesis5150
asked on
How to explode a string and separate each value with single quotes and commas in PHP
The delimiter is a comma that separates each value in the string.
$image = "a.jpg,b.jpg,c.jpg";
I would like each value to output as 'a.jpg', 'b.jpg', 'c.jpg'
Each value within single quotes and separated by a comma.
This is my code so far:
Thanks
$image = "a.jpg,b.jpg,c.jpg";
I would like each value to output as 'a.jpg', 'b.jpg', 'c.jpg'
Each value within single quotes and separated by a comma.
This is my code so far:
$result=$db->singleQuery("SELECT * FROM units WHERE username=?sql AND id=?sql", Array($user,$id));
foreach ($result as $row)
$image = $row["images"];
echo $image;
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I actually found it:
$images = "'".implode("','",array_fi lter($arr) )."'";
Thanks everyone
$images = "'".implode("','",array_fi
Thanks everyone
ASKER
It gave me what I was looking for plus adding array_filter() worked better by eliminating empty values
ASKER
'c.jpg', ''
Thanks