Page 1 of 1

spaces in a string for linking

Posted: Fri Jan 20, 2006 6:44 pm
by blindleaf
Ok i'm trying to link to this other page in this format:

echo "<a href=http://www.website.com/folder/$letter/$art/>Link</a>";

but if the string "$art" has spaces in it, such as "a buck short", the link actually links to this address:

http://www.website.com/folder/a/a

it doesn't keep the whole variable in the link as i need it to. I need it to link to:

http://www.website.com/folder/a/a buck short/

can anyone help me with this probably very basic problem? thanks

Posted: Fri Jan 20, 2006 8:29 pm
by shiznatix

Code: Select all

$str = str_replace(' ', '', $str);
is that what you mean? if you want it to be parsed through the url for whatever reason do:

Code: Select all

$str = str_replace(' ', '%20', $str);

Posted: Fri Jan 20, 2006 9:01 pm
by josh
I usually replace spaces with underscores and then back again,

there's also urlencode()