How to remove comma at the end of a string in PHP

2 Answers

0 votes
$s = "php java c c++,";
 
if (substr($s, -1) == ',') {
  $s = substr($s, 0, -1);
}
 
echo $s;
 
 
 
 
/*
run:
 
php java c c++

*/

 



answered May 18, 2021 by avibootz
0 votes
$s = "php java c c++,";
 
if (substr($s, -1) == ',') {
  $s = rtrim($s, ',');
}
 
echo $s;
 
 
 
 
/*
run:
 
php java c c++

*/

 



answered May 18, 2021 by avibootz

Related questions

2 answers 147 views
2 answers 195 views
1 answer 155 views
1 answer 221 views
2 answers 118 views
1 answer 145 views
...