php explode
Friday, July 28, 2006 8:39:36 PM
keyword1, keyword2, keyword3, keyword4, keyword5, keyword6So the string you see above was inserted by the user, using an input text field. A form was submitted, and the string was stored into a database just as you see it there, possibly with the spaces as
using str_replace. In order to break this single string up into it's seperate keywords, and possiblly output those keywords, you would use a simple php explode function like the below :
<?php
//first insert the string into a variable
$string = "keyword1, keyword2, keyword3, keyword4, keyword5, keyword6";
//execute the explode function
$str = exlode(", ", $string);
//output the keywords one by one using foreach
foreach ($str as $s)
{
echo
"
$s <br />
";
};
?>
So that's about it. The result of the code you see above will output something like this :
keyword1 keyword2 keyword3 keyword4 keyword5 keyword6A simple, but yet extremely useful function of php which I use regularly due to the functionality it offers.














