replace underscores with spaces

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
peok
-


Joined: 16 Jun 2003
Posts: 6

PostPosted: Sun Jul 11, 2004 1:46 am    Post subject: replace underscores with spaces Reply with quote

I tried searching google, but honestly I don't think I know how to put this into php lingo so I didn't come up with much. I want to replace underscores with spaces in a string of text which is in a variable so I can put the newly fomatted string on my page as plain text. If there's a way to then capitalize the first letter of each word that would be awsome too. Is there an easy way to do this? Or even a hard way? I found this but I don't know if it's what I'm looking for. I can't quite comprehend it yet. Thanks for any help.
Back to top View user's profile Send private message
TRUSTAbyss
-


Joined: 29 Oct 2003
Posts: 3752
Location: USA, GA

PostPosted: Sun Jul 11, 2004 4:58 am    Post subject: Reply with quote

Sure , their is a way but you have to know how to use PHP in order
to use it in your script , I have added some examples below !

To Replace _ with a space , use:

Code:
str_replace('_' , ' ' , $string);


To Capitalize every first letter in a word , use:

Code:
ucwords($string);


Note: You need to know how to use PHP in order to use these
type of functions in your scripts , check php.net for usage.

Also if you need a sample script , I will be more than happy to
show you how to use these two functions. Have A Nice Day !
Back to top View user's profile Send private message Visit poster's website
peok
-


Joined: 16 Jun 2003
Posts: 6

PostPosted: Sun Jul 11, 2004 5:39 am    Post subject: Reply with quote

Hey thanks for your reply TRUSTpunk.

It worked great.

This is my code:

Code:
<?php
$gallery_title = $gallery_dir;
$gallery_title = str_replace('_' , ' ' , $gallery_title);
$gallery_title = ucwords($gallery_title);
print($gallery_title);
?>


$gallery_dir is already defined earlier. $gallery_title went in as "gallery_1" and came out "Gallery 1". Thanks again.
Back to top View user's profile Send private message
TRUSTAbyss
-


Joined: 29 Oct 2003
Posts: 3752
Location: USA, GA

PostPosted: Sun Jul 11, 2004 5:48 am    Post subject: Reply with quote

Yep , thats exactly how you use these functions , im
glad I was able to help you , keep learning PHP !

You can buy some PHP books at Barns & Noble
for like $20 each , webmonkey is no help to me.
Back to top View user's profile Send private message Visit poster's website
00squeaky
-


Joined: 11 May 2004
Posts: 60

PostPosted: Mon Jul 12, 2004 10:52 pm    Post subject: Reply with quote

if you store your information in a databas, there is no need to do the charsctor replace thing.
and i have never had any trouble with doing this:
Code:

//example
$mook = 'good boy';
echo"$mook";

_________________
Languages mastered:
HTML,GML,C,PHP,MYSQL (not really a language, but wtf)
Back to top View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group