spaces in a string for linking

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
blindleaf
Forum Newbie
Posts: 6
Joined: Thu Jun 16, 2005 9:36 am

spaces in a string for linking

Post 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
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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);
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

I usually replace spaces with underscores and then back again,

there's also urlencode()
Post Reply