php - Remove last value in a string -


<?php         $values = "aaa,bbb,ccc,ddd,";//remove last comma     $values = "aaa,bbb,,,";//remove commas after bbb aaa,bbb ?> 

how remove commas in example

you can trim "," using below code: use php function rtrim.

<?php      $values = "aaa,bbb,ccc,ddd,";//remove last comma echo rtrim($values,','); echo "<br/>";  $values = "aaa,bbb,,,";//remove commas before bbb aaa,bbb echo rtrim($values,','); ?> 

Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

linux - gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error is not recoverable: exiting now -

sql - MySQL - Finding Empty relations -