How to remove the last three words from a string in PHP

1 Answer

0 votes
$s = "php java c# python c++ swift";
   
$words = explode(" ", $s);
array_splice($words, -3);
 
$s = implode(" ", $words);
        
echo $s;
 
 
 
 
/*
run:
 
php java c#
 
*/

 



answered Nov 28, 2020 by avibootz

Related questions

1 answer 145 views
1 answer 159 views
1 answer 161 views
1 answer 265 views
1 answer 191 views
...