I want to divide words in string by equal parts and then add something in middle.
$string = "hello i am superman and also batman";
$insert = "word";
so i want the result to be
$result= "hello i am superman word and also batman";
What i tried...but below code is very dirty...any easy method please ?
$word = "word";
$arr = explode(" ",$string);
$count = round(sizeof($arr)/2);
$i=0;
foreach($arr as $ok)
{
if($i == $count)
{
$new.=$ok." ".$word;
}
else
{
$new.= $ok." ";
}
$i++;
}
echo trim($new);