Gossamer Forum
Home : Products : DBMan : Installation :

Browser Differences and Special Characters

Quote Reply
Browser Differences and Special Characters
I'm doing a search to an external mapping program from dbman. With IE Explorer 5.0 I have no problems but with Netscape 4.51 I have problems. The issue is spaces in a city name.

I have a datbase with City, State and Postal Code fields among others.
I pass the value of these fields to the external cgi program as follows.

print qq|<a href="http://www.mapblast.com/mblast/map.mb?loc=us&CMD=GEO&AD2=$rec{'Address1'}&AD3=$rec{'City'}+$rec{'Postal_Code'}"> other code goes here </a>

Now with IE 5.0 the Address1 field which has spaces in it are automatically converted to %20 character and the routine works fine.

Netscape doesn't do any conversion and thus the routine doesn't work.

My question -- is there an easy way to do the conversion prior to the <a href link.
I could test those three fields above Address, City and Postal Code for spaces and Convert them -- any ideas on how to do this?

Or is there another work around the browser anomolies.
Quote Reply
Re: Browser Differences and Special Characters In reply to
If the only problem you're running into is spaces, you can use

$rec{'FieldName'} =~ s/ /+/g;

for each field that might have spaces in it.

If you are going to have other characters that might cause problems, there's another subroutine that will do the conversion.

I suppose I might as well give you the subroutine, because someone else will probably ask. Smile

Code:
sub urlencode {
# --------------------------------------------------------
my($toencode) = @_;
$toencode=~s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg;
$toencode=~s/\%2F/\//g;
return $toencode;
}

Then, before you print out your link in html.pl, use

$rec{'FieldName'} = &urlencode($rec{'FieldName'});

(The code above is "borrowed" from Links.)


------------------
JPD





Quote Reply
Re: Browser Differences and Special Characters In reply to
Great -- this is exactly what was needed. I used the sub in the db.cgi file -- works perfectly!
Thanks again