I want to remove the comma off the end of a string. As it is now i am using
$string = substr($string,0,-1);
but that only removes the last
A simple regular expression would work
$string = preg_replace("/,$/", "", $string)
Precede that with:
if(substr($string, -1)==",")
$string = rtrim($string, ',');
Docs for rtrim here
i guess you're concatenating something in the loop, like
foreach($a as $b)
$string .= $b . ',';
much better is to collect items in an array and then join it with a delimiter you need
foreach($a as $b)
$result[] = $b;
$result = implode(',', $result);
this solves trailing and double delimiter problems that usually occur with concatenation