Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 214
  • Last Modified:

more help with spaces, please

Okay so this works:

$location =~ s/ /%20/g;

if I take it out, it doesn't work (in Netscape, but IE is fine).

However, it is replacing a single space with three '%20'

So that what should be "new york" comes out as "new%20%20%20york"

The script works nonetheless, but I think it looks messy.

Anyone know why it's doing this, and how I can fix it?

Thank you.

0
celere
Asked:
celere
  • 5
  • 2
1 Solution
 
TsvetomirCommented:
if it comes to url encoded string:

the standard doesn't allow to use space you should replace them with "+" sign or it's ascii number in hex.
space is ASCII 32 (in HEX it's  20) that's why it becomes %20.

this way you can encode other not allowed(or with special meaning as "/" ) chars - for example !@#$%^&*(),/:
  = ASCII 32 = %20
! = ASCII 33 = %21
" = ASCII 34 = %22
# = ASCII 35 = %23
and s.o. and s.o.

did you get the idea ?

0
 
TsvetomirCommented:
P.S if you want you can strip the aditional spaces and to use  +  it's more readable:

$location = "New   York"
$location =~ s/\s+/+/g;

#now $location is "New+York"
0
 
TsvetomirCommented:
now I sow your other post probably the scripts misses somthing and multiplicates the chars by 3 each time .. I can't tell you where exactly is the mistace becouse I can't see the script here ... but the last probably  will solve the problem.
Beacouse it maj be used somewhere else as hex encoded you can use


$location =~ s/\s+/%20/g;



if this doesn't solve the problem you shold post the script here ...
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
celereAuthor Commented:
I will post the script shortly, but here is how it works thus far.

There is a menu of links with %20 hard coded in it:
<a ref'"http://mysite.com/cgi/read.cgi?newyork::New%20York">

This takes you to the "read.cgi" script, which delimits the :: as $shortname, $longname; opens up and reads $shortname.htm (newyork.htm), and places New York around the page to let the user know where they are.

$page=$ENV{'QUERY_STRING'};
$page=~s/^page=//;
$page =~ tr/ /%20/;
$newadtarget = "$page";
foreach($page)
     {
     ($shortname,$longname)=split(/::/,$_);
     }

Then there is a "post to this page" button (href, not form)
<a href="http://mysite.com/cgi/messages.cgi?$newadtarget">

which then goes to a second script for posting the messages. Here, NS is still reading only one %20 between New and York. After posting it returns to the same script for a "Thank You" page. This is the first occurence of the %20's tripling, as it reads "click here to see your ad" taking you back to <read.cgi..$shortname::$longname>

So I need $longname to be able to take one %20, not three, and I need it to be dynamic; I can't hardcode anything into it.

The message script also prints a link to the ad to appear among the "random message generator". It prints it with 3 %20's. So if someone were to click on that, and subsequently post an ad on the same page, it would print with 9 %20's.

I would like the most efficient way of doing this (keeping my scripts separate however, since they contain a lot of HTML). I will try your idea above, but if you think I should start over with the links, etc. and if you can help me clean it up (it is a little verbose!) I'll increase the points.

Thanks for pointing out I had two questions. I didn't post twice, I posted once and then "edited" it, but there should only be one.


0
 
rj2Commented:
It's not only spaces that are now allowed in URL, there are other characters too. Sample below should get them all.

use URI::Escape;
$_="New     York";
s/ +/ /;
$_=uri_escape($_);
print "$_\n";
0
 
TsvetomirCommented:
????
ARE YOU shure its' like that ??? :
$page =~ tr/ /%20/;

this is a mistake ?!

it should be
$page =~ s/ /%20/g;
# or to have only 1 space:
$page =~ s/\s+/%20/;

tr replaces the chrars from left to their CORESPONDING chars on the rigth side 1 by 1 this means that
if it found space it will replace it with the coresponding char from right side and this is % not %20!

are u sure it's like that ??  I'm amazed that script works like that!

try this and see if it works ...


0
 
celereAuthor Commented:
I replaced all the spaces with +'s and now it works like a charm. Thank You!
0
 
TsvetomirCommented:
you are wellcome :))
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now