epoptai has asked for the wisdom of the Perl Monks concerning the following question:
I've got a string with text and html tags destined for a process that will damage the html. So I want to temporarily replace the html with placeholders while storing a "placeholder => html" map in a hash, so it can be restored after the destructive process.
As an example I need to turn this:
Into this string and hash:$str = qq~This <b>contains</b> both text and <a href="http://www.w3c.org">ht +ml</a>.~;
Then I can process the string and restore the html with something like:$str = qq~This <1>contains<2> both text and <3>html<4>.~; $html = { 1 => 'b', 2 => '/b', 3 => 'a href="http://www.w3c.org"', 4 => '/a' }
I thought this would be easy, but I'm still staring at the wall. Thanks.$str =~ s|<(\d+)>|<$$html{$1}>|g;
--
Check out my Perlmonks Related Scripts like framechat,
reputer, and xNN.
|
---|
Replies are listed 'Best First'. | |
---|---|
(jeffa) Re: Temporarily strip HTML
by jeffa (Bishop) on Jul 19, 2002 at 01:09 UTC | |
Re: Temporarily strip HTML
by DamnDirtyApe (Curate) on Jul 19, 2002 at 03:00 UTC | |
Re: Temporarily strip HTML
by Juerd (Abbot) on Jul 19, 2002 at 06:45 UTC | |
Temporarily strip HTML (solved!)
by epoptai (Curate) on Jul 20, 2002 at 00:54 UTC |
Back to
Seekers of Perl Wisdom