/ Published in: PHP
URL: http://www.totaldream.org
This is the PHP equivalent to http://snipplr.com/view/12074/delete-last-comma/
You will use only the deleteLastComma() function!
Expand |
Embed | Plain Text
function instrrev($n,$s) { } function mid($s,$x,$w="") { //$w is optional } function deleteLastComma($valStr) { $lastCommaPos = instrrev($valStr, ","); $valStr = mid($valStr, 1, $lastCommaPos - 1); return $valStr; }
Comments
Subscribe to comments
You need to login to post a comment.

you could probably do this with a one-liner regular expression like this (shooting from the hip, untested)
function deleteLastComma($str) { return preg_replace("/(.*),([^,]+)$/", "$1$2", $str); }