Link to home
Start Free TrialLog in
Avatar of Genesis5150
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:

$result=$db->singleQuery("SELECT * FROM units WHERE username=?sql AND id=?sql", Array($user,$id));

foreach ($result as $row)

$image = $row["images"];

echo $image;

Open in new window


Thanks
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Genesis5150
Genesis5150

ASKER

Thanks Ryan that worked but is there a way to limit empty spaces? Not to show

'c.jpg', ''

Thanks
I actually found it:

$images = "'".implode("','",array_filter($arr))."'";

Thanks everyone
It gave me what I was looking for plus adding array_filter() worked better by eliminating empty values