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

2 Answers

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
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

Related questions

2 answers 188 views
1 answer 200 views
200 views asked May 18, 2021 by avibootz
2 answers 160 views
1 answer 154 views
1 answer 221 views
2 answers 118 views
...