Solved

more help with spaces, please

Posted on 2002-06-13
8
185 Views
Last Modified: 2010-03-05
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
Comment
Question by:celere
  • 5
  • 2
8 Comments
 
LVL 3

Expert Comment

by:Tsvetomir
ID: 7076036
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
 
LVL 3

Expert Comment

by:Tsvetomir
ID: 7076040
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
 
LVL 3

Accepted Solution

by:
Tsvetomir earned 50 total points
ID: 7076058
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
 

Author Comment

by:celere
ID: 7076141
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 10

Expert Comment

by:rj2
ID: 7076295
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
 
LVL 3

Expert Comment

by:Tsvetomir
ID: 7076674
????
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
 

Author Comment

by:celere
ID: 7111444
I replaced all the spaces with +'s and now it works like a charm. Thank You!
0
 
LVL 3

Expert Comment

by:Tsvetomir
ID: 7117940
you are wellcome :))
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
perl search and replace 6 165
PERL get the value for query 4 145
How to send output of ping to syslog (with timestamp and optional comments) 3 186
transpose into pipe delemited 8 67
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now