PHP : remove char.

Out of context: Reply #5

  • Started
  • Last post
  • 5 Responses
  • mike0

    pixter's recommendation is nicer if you are using an array already, but if you have the value as a string and you just want to chop the last character then try this...

    $sStr = substr(trim($sMyStr), 0, strlen(trim($sMyStr)) - 1);

    that will give you the entire string back minus the last char and any spaces that may follow.

    http://us3.php.net/manual/en/fun…

    this is going to be a lot faster if the items are not in an array... otherwise, use pixter's suggestion... although his syntax is wrong...

    $sStr = "bob, sue, tom, ";
    $aStr = explode(", ", $sStr);
    array_pop($aStr);
    $sStr = implode(", ", $aStr);

View thread