Gossamer Forum
Home : Products : DBMan : Installation :

Converting Spaces and "&"

Quote Reply
Converting Spaces and "&"
Hi,

I am going to use the following code

Code:
@fields = split (/\,/, $db_select_fields{'Category'});
foreach $category (@fields) {
print "<OPTION VALUE=\"$db_script_link_url&Category=$category&view_records=1\">$category";
}

I have no problem in listing the actual data, but when I have the link, it includes the spaces and the "&" (Vitamins & Supplements) in the link. When that happens, I get "0" search result, because it has the spaces. How can I get rid of them only in the link (Value="$category"), but not in the actual data that will be the drop down list

Thank You
Quote Reply
Re: Converting Spaces and "&" In reply to
Add the following to db.cgi

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

Then add the following bolded line and character to your loop:

Code:
@fields = split (/\,/, $db_select_fields{'Category'});
foreach $category (@fields) {
$category1 = &urlencode($category);
print "<OPTION VALUE=\"$db_script_link_url&Category=$category1&view_records=1\">$category";
}

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







[This message has been edited by JPDeni (edited June 04, 1999).]