...

View Full Version : HELP: Passing value from DB in URL - spaces problem



martincrumlish
01-24-2003, 05:13 PM
Hi,

I have a problem. I have written a web app that takes results from an Informix DB. this DB is part of a legacy system and as such, I cant change the data in it. i am only writing something that outputs the data.

One of the DB fields holds placenems and these in some cases are two words ie: San Diego. Now, there is a second page which produces further results depending on the placename. I pass the placename value to the next page in the URL but, and here's the problem:

Normally, I pass the value like so: link.php?name=$placename If the placename is Dublin then the link would be


link.php?name=Dublin

However, if the placename is San Diego this becomes


link.php?name=San Diego


When I try to pass this in the URL it doesnt work and only passes it like this:


link.php?name=San


As such, this messes up the query that relies on the $name value on the link.php page.

Anyone got any ideas?

Thanks,
Martin

Jeewhizz
01-24-2003, 05:29 PM
THere is a PHP function that does this - it'll chuck %20 instead of a space, which the browser will read as a space...

and that function is.. urlencode() - www.php.net/urlencode

Jee

martincrumlish
01-24-2003, 05:54 PM
Thanks.

Because of some of the characters in my query, urlencode doesnt work properly so I used this instead:


$string = ereg_replace (" ", "%20", $string);


This works apart from one thing.....the value in the DB also has a load of spaces after the last letter of the word.

ie: "SAN DIEGO "

when I use:
$string = ereg_replace (" ", "%20", $string);

this would give "SAN%20DIEGO%20%20%20%20%20%20%20%20%20%20" Is there away to replace the first space and then trim off all the rest?

Nightfire
01-24-2003, 06:11 PM
Use trim() (http://www.php.net/manual/en/function.trim.php)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum