View previous topic :: View next topic |
Author |
Message |
peok -
Joined: 16 Jun 2003 Posts: 6
|
Posted: Sun Jul 11, 2004 1:46 am Post subject: replace underscores with spaces |
|
|
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 |
|
 |
TRUSTAbyss -
Joined: 29 Oct 2003 Posts: 3752 Location: USA, GA
|
Posted: Sun Jul 11, 2004 4:58 am Post subject: |
|
|
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:
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 |
|
 |
peok -
Joined: 16 Jun 2003 Posts: 6
|
Posted: Sun Jul 11, 2004 5:39 am Post subject: |
|
|
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 |
|
 |
TRUSTAbyss -
Joined: 29 Oct 2003 Posts: 3752 Location: USA, GA
|
Posted: Sun Jul 11, 2004 5:48 am Post subject: |
|
|
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 |
|
 |
00squeaky -
Joined: 11 May 2004 Posts: 60
|
Posted: Mon Jul 12, 2004 10:52 pm Post subject: |
|
|
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 |
|
 |
|