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 147 views
1 answer 160 views
1 answer 163 views
1 answer 268 views
1 answer 192 views
...