We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
replacing charecters in php
Topic Started: Mar 30 2005, 03:41 PM (231 Views)
kingy
1 in 10 people understands binary, the other 1 doesn't
[ *  *  *  *  *  * ]
Me again

Is their a way, in php, of taking a variable containing "hello world" and turning it into "hello_world"

Thanks

Kingy
Offline Profile Quote Post Goto Top
 
Rory
Member Avatar
i;m a mess
[ *  *  *  *  *  *  * ]
I'm not sure if this is the best way to do it, but the first example seems to do what you want:

http://uk.php.net/manual/en/function.preg-replace.php

edit: this seems to be the better one:

http://uk2.php.net/str_replace

so:

Code:
 
<?php

$text = "Hello World";
$replace = " ";
$newText = str_replace($replace, "_", $text);

?>
Offline Profile Quote Post Goto Top
 
kingy
1 in 10 people understands binary, the other 1 doesn't
[ *  *  *  *  *  * ]
thankyou very much
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Technology Chat · Next Topic »
Add Reply