Reputation: 63
I have a string named $words = "Unbelievable
.
I want the output to be U nbelievable
I tried this code:
implode(" ", str_split($words, 2))." ";
It's working but it affects on every 2 characters in the string
.
I got this Un be li ev ab le
using the code above.
I want only to add a space after first character in a string
Upvotes: 2
Views: 2211
Reputation: 8369
You can use substr() or substr_replace() for this purpose. Try with either
$words = "Unbelievable";
echo substr($words, 0, 1) . ' ' . substr($words, 1);
or
echo substr_replace($words," ", 1, -strlen($words));
Upvotes: 5
Reputation: 2330
$words = "Unbelievable".
$word = substr_replace($words," ", 1, -strlen($words));
Upvotes: 0