How to merge the first two words in a string with PHP

1 Answer

0 votes
$s = "php java c# c++ python c#";

echo $s . "<br>";

$arr = explode(' ', $s);

$first_two_words = $arr[0] . " " . $arr[1];

$s = str_replace($first_two_words, str_replace(' ', '', $first_two_words), $s);

echo $s;



/*
run

php java c# c++ python c#
phpjava c# c++ python c#

*/

 



answered Dec 1, 2020 by avibootz

Related questions

...