So when submitting a form, part of the results in $_POST are:
[keywords] => Array ( [0] => Acupuncture [1] => Aromatherapy )
$_POST['keywords'] may or may not have more than 1 element in the array. In the case it does, I create a string with each of the elements seperated by ', '. This obviously results in a string with ', ' tacked on at the end, which I need to remove, however I'm having trouble doing so.
Here is my code:
$keywords = $_POST['keywords'];
$knum = count($keywords);
if($knum > 1)
{
for($i=0; $i<=$knum; $i++)
{
$klist .= $keywords[$i] . ", ";
}
$klist = substr($klist,0,-2);
}
echo $klist;
When I run the script, I get:
Acupuncture, Aromatherapy,
Does using a negative value in substr for the length attribute not work? I have seen it used in several places on the web before now.
If it doesn't work, what is the best way to remove those last two characters from the string?
Cheers
James