Help with explode

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jaay
Forum Newbie
Posts: 1
Joined: Tue Dec 22, 2009 6:30 am

Help with explode

Post 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]);
}
MichaelR
Forum Contributor
Posts: 148
Joined: Sat Jan 03, 2009 3:27 pm

Re: Help with explode

Post by MichaelR »

Code: Select all

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