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 320 views
1 answer 271 views
271 views asked May 18, 2021 by avibootz
2 answers 286 views
1 answer 256 views
1 answer 329 views
2 answers 230 views
...