Page 1 of 1

Help with explode

Posted: Tue Dec 22, 2009 6:38 am
by jaay
Hi, I am new to php and stuck with a problem, need some help

I have a field in mysql table that stores tags separated by comma. Now I am using the explode function to separate the tags and display them separtely ... it works fine if theres a space after the comma .... that is like, tag1, tag2, tag3 etc... but if the user doesnt leave a space after the comma ..it doesnt work .. say for example, tag1, tag2,tag3 ..in this case only tag1 and tag2 gets displayed not tag3 .... what am i doing wrong here? here's my code ..

$stags = explode(", ", $a);
$result = count($stags);

for($n = 0; $n < $result; $n++)
{
$stags = explode (",", $a);
echo trim($stags [$n]);
}

Re: Help with explode

Posted: Tue Dec 22, 2009 6:51 am
by MichaelR

Code: Select all

 
$stags = explode(",", $a);
$result = count($stags);