Jump to content

Archived

This topic is now archived and is closed to further replies.

clarencek

Help to change string from space to +

Recommended Posts

Hi, I'm a bit new at php and need help with some string manipulation.

I'm getting a variable out of my database with this call:  $t_city = $row['t_city'];  Basically $t_city = "New York".  What I want to do is manipulate the string such that it becomes "New+York".

I was trying this, but it doesn't seem to work:
$t_city = str_replace(\' \',\'+\',$t_city);

What am I doing wrong?

Share this post


Link to post
Share on other sites
$t_city = str_replace(' ','+',$t_city);

No need to escape :)

Orio.

Share this post


Link to post
Share on other sites
[code]<?php

$text = "hello this is a string";
$text = str_replace( " ", "+", $text );

echo $text;

?>[/code]

This is how :)

Share this post


Link to post
Share on other sites
hahaha...i hear ya.  there's no reason i should be staying up till 4 AM two nights in a row.  i don't think i'll pull a 3rd night.  time for me to go to bed!

Share this post


Link to post
Share on other sites
If this is about adding the value to a url, you may want to look at [url=http://www.php.net/urlencode]urlencode[/url]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.