Welcome to WebmasterWorld Guest from 23.22.200.6

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

adding space after 3 spaces from the end

     
9:41 am on Jul 8, 2011 (gmt 0)

Junior Member

5+ Year Member

joined:July 17, 2006
posts:137
votes: 0


I am trying to put a space in a string after 3 characters from the end. So if I use the word HELLO, i need the space to show after the E so reading HE LLO.

Thanks
11:41 am on July 8, 2011 (gmt 0)

Administrator

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
posts:12537
votes: 0


What if the string is not 3 characters long? :)
<pre> 
<?php
$strings = array('HELLO', 'One', '1', '');
foreach ($strings as $string) {
if (strlen($string) > 3 && $lastThree = substr($string, -3)) {
$string = substr_replace($string, " {$lastThree}", -3);
}
var_dump($string);
}
?>
</pre>
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members