For Programmers: Free Programming Magazines  


Home > Archive > PERL CGI Beginners > May 2004 > Escaping quotes in variable content









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Escaping quotes in variable content
Jan Eden

2004-05-22, 11:32 am

Hi all,

how can I escape quotes within a variable's content? I use the following di=
rective to fill an HTML form:

<input type=3D"text" name=3D"frage_text" size=3D"100" value=3D"$frage_text"=
/>

Unfortunately, if $frage_text contains a double quote, the browser will sto=
p displaying the string at that point.

I tried to escape the quotes in a Perl way

$frage_text =3D~ s/"/\\"/g;

but that did not help.
=20
Any suggestion is appreciated.
=20
Thanks,
=20
Jan
--=20
Common sense is what tells you that the world is flat.
David Dorward

2004-05-22, 11:32 am

On 11 May 2004, at 14:58, Jan Eden wrote:
> how can I escape quotes within a variable's content? I use the
> following directive to fill an HTML form:
> <input type="text" name="frage_text" size="100" value="$frage_text" />
> Unfortunately, if $frage_text contains a double quote, the browser
> will stop displaying the string at that point.
> I tried to escape the quotes in a Perl way
> $frage_text =~ s/"/\\"/g;


In HTML characters are 'escaped' by converting them to entities.
&entityName; Quote marks are "

You probably want to use escapeHTML() from the CGI module.

--
David Dorward
<http://dorward.me.uk/>
<http://blog.dorward.me.uk/>

Jan Eden

2004-05-22, 11:32 am

Hi David,

David Dorward wrote on 11.05.2004:

>On 11 May 2004, at 14:58, Jan Eden wrote:
>
>In HTML characters are 'escaped' by converting them to entities.
>&entityName; Quote marks are "
>
>You probably want to use escapeHTML() from the CGI module.


Doh. I have been working on the script for several hours now and forgot the=
most simple things about HTML.

Thanks,

Jan
--=20
Common sense is what tells you that the world is flat.
Ash Singh

2004-05-22, 11:32 am



Try this:
<input type=\"text\" name=\"frage_text\" size=\"100\" value=\"$frage_text\">



-----Original Message-----
From: Jan Eden [mailto:lists@janeden.org]
Sent: 11 May 2004 03:59 PM
To: Perl Lists
Subject: Escaping quotes in variable content

Hi all,

how can I escape quotes within a variable's content? I use the following
directive to fill an HTML form:

<input type="text" name="frage_text" size="100" value="$frage_text" />


Unfortunately, if $frage_text contains a double quote, the browser will stop
displaying the string at that point.

I tried to escape the quotes in a Perl way

$frage_text =~ s/"/\\"/g;

but that did not help.

Any suggestion is appreciated.

Thanks,

Jan
--
Common sense is what tells you that the world is flat.

Ash Singh

2004-05-22, 11:32 am

This is better, replace the quotes with nothing and then build your input
tag.

#!/usr/bin/perl

use CGI;
use strict;

my $cgi = new CGI; print $cgi->header;
my $query = CGI::new();

my $frage_text= "\"Hello World\"";

$frage_text =~ s/"//g;

print "<form name=\"test\" action=\"http://www.somewhere.com\">\n";
print " <input type=\"text\" name=\"frage_text\" size=\"100\"
value=\"$frage_text\" />\n";
print "</form>\n";

I hope this helps
Regards Ash.



-----Original Message-----
From: Jan Eden [mailto:lists@janeden.org]
Sent: 11 May 2004 04:21 PM
To: David Dorward; Perl Lists
Subject: Re: Escaping quotes in variable content

Hi David,

David Dorward wrote on 11.05.2004:

>On 11 May 2004, at 14:58, Jan Eden wrote:
>
>In HTML characters are 'escaped' by converting them to entities.
>&entityName; Quote marks are "
>
>You probably want to use escapeHTML() from the CGI module.


Doh. I have been working on the script for several hours now and forgot the
most simple things about HTML.

Thanks,

Jan
--
Common sense is what tells you that the world is flat.

--
To unsubscribe, e-mail: beginners-cgi-unsubscribe@perl.org
For additional commands, e-mail: beginners-cgi-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>

Wiggins D Anconia

2004-05-22, 11:32 am

Please bottom post...

> This is better, replace the quotes with nothing and then build your input
> tag.
>


Better? You have destroyed the data. Stay away from my information
with your substituitions.....

[snip code that should not be used in production]

>
> I hope this helps


Anyone reading the archive, please don't do this. escapeHTML or
HTML::Entities should do very well.

http://danconia.org

>
>
> -----Original Message-----
> From: Jan Eden [mailto:lists@janeden.org]
> Sent: 11 May 2004 04:21 PM
> To: David Dorward; Perl Lists
> Subject: Re: Escaping quotes in variable content
>
> Hi David,
>
> David Dorward wrote on 11.05.2004:
>
>
> Doh. I have been working on the script for several hours now and

forgot the
> most simple things about HTML.
>
> Thanks,
>
> Jan



Jan Eden

2004-05-22, 11:32 am

jon@hogue.org wrote on 11.05.2004:

>
>This wasn't really the question, but...=20
>If you have to write html within perl, use qq( ) instead of "".
>It's a lot easier to read, and much less error prone.
>
>ie,
>print qq(
><form name=3D"test" action=3D"http://www.somewhere.com">
> <input type=3D"text" name=3D"frage_text" size=3D"100" value=3D"$frage_=

text" />
></form>
> );
>


I did use qq{} quoting within the Perl script in the first place. My proble=
m was related to quoting within a double-quoted HTML attribute, e.g.

<input value=3D"This "person"" />

Thanks,

Jan
--=20
Either this man is dead or my watch has stopped. - Groucho Marx
Edvaldo Barbosa GuimarãEs

2004-05-22, 11:32 am

Try $frage_text =3D~ s/\"/\\"/g; I think it will work better this way.=20

Edvaldo Guimar=E3es
Marketing Support - Latin America
UGS PLM Solutions Brasil
An EDS Company
Tel.: +55-11-4224-7153
Fax: +55-11-4224-7107


-----Original Message-----
From: Ash Singh [mailto:AshS@Emessagex.com]
Sent: Tuesday, May 11, 2004 11:44 AM
To: 'Jan Eden'; Perl Lists
Subject: RE: Escaping quotes in variable content


Try this:
<input type=3D\"text\" name=3D\"frage_text\" size=3D\"100\" =
value=3D\"$frage_text\">



-----Original Message-----
From: Jan Eden [mailto:lists@janeden.org]
Sent: 11 May 2004 03:59 PM
To: Perl Lists
Subject: Escaping quotes in variable content

Hi all,

how can I escape quotes within a variable's content? I use the following
directive to fill an HTML form:

<input type=3D"text" name=3D"frage_text" size=3D"100" =
value=3D"$frage_text" />


Unfortunately, if $frage_text contains a double quote, the browser will =
stop
displaying the string at that point.

I tried to escape the quotes in a Perl way

$frage_text =3D~ s/"/\\"/g;

but that did not help.

Any suggestion is appreciated.

Thanks,

Jan
--
Common sense is what tells you that the world is flat.


--
To unsubscribe, e-mail: beginners-cgi-unsubscribe@perl.org
For additional commands, e-mail: beginners-cgi-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>=20

jon@hogue.org

2004-05-22, 11:32 am


> print "<form name=\"test\" action=\"http://www.somewhere.com\">\n";
> print " <input type=\"text\" name=\"frage_text\" size=\"100\"
> value=\"$frage_text\" />\n";
> print "</form>\n";


This wasn't really the question, but...
If you have to write html within perl, use qq( ) instead of "".
It's a lot easier to read, and much less error prone.

ie,
print qq(
<form name="test" action="http://www.somewhere.com">
<input type="text" name="frage_text" size="100" value="$frage_text" />
</form>
);


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com