| | |
Replace a space with an underscore SOLVED
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Nov 2007
Posts: 86
Reputation:
Solved Threads: 6
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.
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
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 Syntax (Toggle Plain Text)
<?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
•
•
•
•
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?
Last edited by nav33n; Feb 19th, 2008 at 12:07 am.
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Nov 2006
Posts: 224
Reputation:
Solved Threads: 31
hi, I do not have any special PHP knowledge, so I would like someone to give me a code for this; I have a "text.txt" file on my server, which has underscores in it. I want a PHP code which replaces all the underscores with spaces and then save the txt. thanks
--
Index of mp3
Index of mp3
![]() |
Other Threads in the PHP Forum
- Previous Thread: Str_Replace / Preg_replace
- Next Thread: connectivity problem
| Thread Tools | Search this Thread |
apache api array beginner binary body broken cakephp checkbox class cms code computing cron curl database date date/time delete display dynamic echo email error file files filter folder form forms function functions gc_maxlifetime global google host href htaccess html image include insert ip javascript joomla limit link list login mail memmory memory menu mlm msqli_multi_query multiple mycodeisbad mysql navigation oop parameter parsing paypal pdf php problem query radio random recourse recursion regex remote script search seo server sessions sms snippet source space sql static syntax system table thesishelp tutorial update upload url validator variable video web webdesign wordpress xml youtube






