...

View Full Version : Spilt string based off space char



moos3
08-16-2007, 02:59 PM
I have a sql field that holds tags for my blog. I'm trying to figure out how to split them up. They have a space between each tag. I've looked at str_split function and all the examples show that you have to know long each word is. I need to load them into a array so I can output each on as a link. Any siggestions?

rafiki
08-16-2007, 03:02 PM
explode()? (http://php.net/explode)

whizard
08-16-2007, 05:11 PM
explode(" ",$string);

HTH
Dan

moos3
08-16-2007, 05:25 PM
so if I do explode


$string = "tag1 tag2 tag2 tag3";
array = explode(" ",$string);


this will give me each tag?

whizard
08-16-2007, 06:02 PM
It should, feel free to try it, messing around and seeing what works and what doesn't is the best way to learn

:thumbsup:

Dan

Pennimus
08-16-2007, 09:30 PM
Don't forget your dollar symbol in front of "array". Then loop through the array, building and outputting your links as you go.

whizard
08-16-2007, 09:55 PM
Good point Pennimus I missed that..

Dan

rafiki
08-17-2007, 02:45 AM
$string = "tag1 tag2 tag2 tag3";
$parts = explode(" ", $string);
echo $parts[1]; // echo's tag2



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum