homepage Welcome to WebmasterWorld Guest from 54.196.194.204
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
adding space after 3 spaces from the end
ahmed24




msg:4336862
 9:41 am on Jul 8, 2011 (gmt 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

 

coopster




msg:4336880
 11:41 am on Jul 8, 2011 (gmt 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>

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved