Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Perl equivalent of htmlspecialchars()

0 views
Skip to first unread message

Yogi

unread,
May 20, 2008, 2:43:32 AM5/20/08
to
Hi,

I am looking for perl equivalent of PHP functions htmlspecialchars()
and stripslashes() to parse a html page. Any pointers will be of
great help.

Regards,
-Yogesh

Ben Bullock

unread,
May 20, 2008, 3:35:11 AM5/20/08
to
Yogi <yogeshk...@gmail.com> wrote:
> I am looking for perl equivalent of PHP functions htmlspecialchars()

There are lots of ways to do it, try the HTML::Entities module:

http://search.cpan.org/~gaas/HTML-Parser-3.56/lib/HTML/Entities.pm

> and stripslashes() to parse a html page.

stripslashes seems to be something like

s/\\//g;

in Perl.

Gunnar Hjalmarsson

unread,
May 20, 2008, 3:39:03 AM5/20/08
to
Yogi wrote:
> I am looking for perl equivalent of PHP functions htmlspecialchars()

That would be CGI.pm's escapeHTML() function.

> and stripslashes()

Don't know about any function. I'd make use of the s/// operator.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Yogi

unread,
May 20, 2008, 3:51:19 AM5/20/08
to
On May 20, 12:35 pm, benkasminbull...@gmail.com (Ben Bullock) wrote:
> Yogi <yogeshkagra...@gmail.com> wrote:
> > I am looking forperlequivalent of PHP functions htmlspecialchars()

>
> There are lots of ways to do it, try the HTML::Entities module:
>
> http://search.cpan.org/~gaas/HTML-Parser-3.56/lib/HTML/Entities.pm
>
> > andstripslashes() to parse a html page.
>
> stripslashesseems to be something like
>
> s/\\//g;
>
> inPerl.

Thanks Ben for your input. HTML::Entities seems to solve my
puzzle. :)
will use Regex for stripslashes. Thanks again.

Tad J McClellan

unread,
May 20, 2008, 7:54:22 AM5/20/08
to
Yogi <yogeshk...@gmail.com> wrote:
> On May 20, 12:35 pm, benkasminbull...@gmail.com (Ben Bullock) wrote:


>> stripslashesseems to be something like
>>
>> s/\\//g;

> will use Regex for stripslashes. Thanks again.


Transliteration is more appropriate for operating on characters
(regexes are better for operating on patterns):


tr/\\//d;


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"

Gunnar Hjalmarsson

unread,
May 20, 2008, 7:49:03 AM5/20/08
to
Tad J McClellan wrote:
> Yogi <yogeshk...@gmail.com> wrote:
>> On May 20, 12:35 pm, benkasminbull...@gmail.com (Ben Bullock) wrote:
>>>
>>> stripslashesseems to be something like
>>>
>>> s/\\//g;
>>
>> will use Regex for stripslashes. Thanks again.
>
> Transliteration is more appropriate for operating on characters
> (regexes are better for operating on patterns):
>
> tr/\\//d;

True, but are we really talking about simple character removals here? I
thought we were rather talking about something like

s/(^|[^\\])\\(['"\\0])/$1.($2 eq '0' ? "\0" : $2)/eg

http://www.php.net/manual/en/function.stripslashes.php

Dr.Ruud

unread,
May 21, 2008, 3:12:11 PM5/21/08
to
Ben Bullock schreef:

> stripslashes seems to be something like
>
> s/\\//g;
>
> in Perl.

I find it funny that it removes backslashes and not is called
stripbackslashes.

--
Affijn, Ruud

"Gewoon is een tijger."

smallpond

unread,
May 21, 2008, 4:15:13 PM5/21/08
to
Dr.Ruud wrote:
> Ben Bullock schreef:
>
>
>>stripslashes seems to be something like
>>
>>s/\\//g;
>>
>>in Perl.
>
>
> I find it funny that it removes backslashes and not is called
> stripbackslashes.
>

The name in perlop is "leaning toothpick syndrome".
--S
** Posted from http://www.teranews.com **

0 new messages