Current location: Hot Scripts Forums » Programming Languages » PHP » Space out string


Space out string

Reply
  #1 (permalink)  
Old 10-02-05, 07:29 AM
dihan dihan is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
Space out string

Hi,

If a string were to be "FRIDAY" how can i make that into "F R I D A Y"

D
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 10-02-05, 10:40 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
PHP Code:

$letters preg_replace('~([a-z])~i''\\1 ''Friday');


print_r($letters); 
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 10-02-05, 03:21 PM
Richard's Avatar
Richard Richard is offline
Wannabe Coder
 
Join Date: Sep 2005
Location: Oxford, UK
Posts: 239
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by NeverMind
PHP Code:

$letters preg_replace('~([a-z])~i''\\1 ''Friday');


print_r($letters); 
How do mixed strings work?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 10-02-05, 03:22 PM
dennispopel dennispopel is offline
Coding Addict
 
Join Date: Mar 2005
Posts: 263
Thanks: 0
Thanked 0 Times in 0 Posts
$letters = trim(preg_replace('~([a-z])~i', '\\1 ', 'Friday'));
print_r($letters);

Otherwise there will be an extra space after the last letter.
__________________
onPHP5.com - PHP5: Articles, News, Tutorials, Interviews, Software and more
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 10-02-05, 03:25 PM
Richard's Avatar
Richard Richard is offline
Wannabe Coder
 
Join Date: Sep 2005
Location: Oxford, UK
Posts: 239
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by dennispopel
$letters = trim(preg_replace('~([a-z])~i', '\\1 ', 'Friday'));
print_r($letters);

Otherwise there will be an extra space after the last letter.
Also, for more flixability, you could use
PHP Code:

$letters = [b]trim[/b](preg_replace('~([a-z])~i''\\1 '$theString)); 

print_r($letters); 
Then set whatever value you like to $theString.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 10-05-05, 10:50 AM
dihan dihan is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
Works great.

Thanks guys
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Return String values from a object saved in an array mr_wazzup Everything Java 1 04-15-05 10:11 AM
ASP syntax error stuckonaproject ASP 8 12-14-04 11:30 AM
One Week Special - 50% Extra Hosting Space - www.deasoft.com bjdea1 General Advertisements 0 06-16-04 06:23 AM
Declared Functions skipper23 PHP 4 12-17-03 11:06 AM
index page not showing up skipper23 PHP 3 12-15-03 02:10 PM


All times are GMT -5. The time now is 08:29 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.