Forum Moderators: coopster

Message Too Old, No Replies

dealing with php string..

simple question!

         

smagdy

5:58 pm on May 20, 2005 (gmt 0)

10+ Year Member



I got a word from the mysql...

for ex. "myWord 100" i want to change it with php to "myWord_100"

so how to do it?

Thanks in advance

someone

6:11 pm on May 20, 2005 (gmt 0)

10+ Year Member



$var1 = "myword 100";
$var2 = explode(" ", $var1);
$var3 = implode("_", $var2);

give that a try.

dreamcatcher

6:19 pm on May 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or use str_replace

$var = "myWord 100";
$var = str_replace(" ", "_", $var);

echo $var;

dc

ergophobe

8:24 pm on May 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If it's an entire field and you want to get rid of all spaces, you can also just do it via the DB server as

SELECT REPLACE(myfield, ' ', '_') as myURL FROM table1

smagdy

9:37 pm on May 20, 2005 (gmt 0)

10+ Year Member



Thanks a lot i will try them all now