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

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -