User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 392,038 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,329 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1098 | Replies: 2
Reply
Join Date: Nov 2007
Posts: 86
Reputation: sagedavis is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 6
sagedavis sagedavis is offline Offline
Junior Poster in Training

Solution Replace a space with an underscore SOLVED

  #1  
Feb 18th, 2008
Sometimes it's just something so simple.
I have been racking my brain, searching the net, for, litterally, 6 hours. Looking to do the following.
If the user puts "this phrase" into the form field, it will send to the database "this_phrase".
Hours and hours of research, solutions using preg_replace with all sorts of regular expressions, and other regexp functions, which spit out error after error, or got me nowhere near where I wanted to be with this.

Finally, I look up str_replace and behold the pot of gold that made it ever so simple.
I am posting this for those of you who have struggled with this, in hopes that it just might save you those hours.

It was such a simple solution.
<?PHP
$name = $_POST[name];
$pagelink = str_replace(" ","_",$name);
?>

I do not know why it is, with all of the sites that talk about replacing a space with an underscore, none of them gave this, ever so simple answer. Maybe it just doesn't look as cool as all of that regular expression stuff?

Maybe I just have no google skills?
Anyway, there is a rather huge weight lifted off of my shoulders now.
Sage
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 238
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: Replace a space with an underscore SOLVED

  #2  
Feb 18th, 2008
I do not know why it is, with all of the sites that talk about replacing a space with an underscore, none of them gave this, ever so simple answer.
What did you search for
Maybe it just doesn't look as cool as all of that regular expression stuff?
No. regular expressions are slower than string functions. Regular expressions are preferred only for complicated string matching and stuff.
Last edited by nav33n : Feb 18th, 2008 at 11:07 pm.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Nov 2007
Posts: 86
Reputation: sagedavis is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 6
sagedavis sagedavis is offline Offline
Junior Poster in Training

Re: Replace a space with an underscore SOLVED

  #3  
Feb 18th, 2008
Nav33
Hey bud... :-)
I can't even remember what all I searched for now...
I am not good at regular expressions anyway, lol so, I'm ok with trying to work around them.
Thanks
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

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

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Other Threads in the PHP Forum

All times are GMT -4. The time now is 11:08 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC