Delete Last Comma in a string


/ Published in: PHP
Save to your folder(s)

This is the PHP equivalent to http://snipplr.com/view/12074/delete-last-comma/

You will use only the deleteLastComma() function!


Copy this code and paste it in your HTML
  1. function instrrev($n,$s) {
  2. $x=strpos(chr(0).strrev($n),$s)+0;
  3. return (($x==0) ? 0 : strlen($n)-$x+1);
  4. }
  5.  
  6. function mid($s,$x,$w="") { //$w is optional
  7. if ($w) {return substr($s,$x-1,$w);}
  8. else {return substr($s,$x-1);}
  9. }
  10.  
  11. function deleteLastComma($valStr) {
  12. $lastCommaPos = instrrev($valStr, ",");
  13. $valStr = mid($valStr, 1, $lastCommaPos - 1);
  14. return $valStr;
  15. }

URL: http://www.totaldream.org

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.