Welcome to WebmasterWorld Guest from 54.211.136.250

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)

5+ Year Member



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 Jul 8, 2011 (gmt 0)

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



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>
 

Featured Threads

Hot Threads This Week

Hot Threads This Month