SFLEX has asked for the wisdom of the Perl Monks concerning the following question:
My HTML Escape code.codepost { background-color: #ffffff; width: 500px; height: auto; white-space: nowrap; overflow: scroll; padding-left: 2px; padding-bottom: 5px; }
The main codesub html_escape { my $text = shift; return '' unless $text; #$text =~ s{\;}{#59;}gso; $text =~ s{&}{&}gso; #$text =~ s{#59;}{;}gso; $text =~ s{"}{"}gso; $text =~ s{ }{ \ }gso; $text =~ s{\*}{*}gso; $text =~ s{<}{<}gso; $text =~ s{>}{>}gso; $text =~ s{'}{'}gso; $text =~ s{\)}{)}gso; $text =~ s{\(}{(}gso; $text =~ s{\\}{\}gso; # need this! $text =~ s{\t}{ \ \ \ }gso; $text =~ s{\|}{\|}gso; # going to keep this $text =~ s{\n}{<br>}gso; $text =~ s{\cM}{}gso; return $text; }
$message =~ s~<br>~=br=~isg; while ($message =~ s{\[code\]([\S\s].+?[\S\s])\[/code\]} { my $tmp = $1; $tmp =~ s!<!<!g; $tmp =~ s!>!>!g; # ' $tmp =~ s!:!:!g; $tmp =~ s!\[![!g; $tmp =~ s!\\!\!g; $tmp =~ s!\]!]!g; $tmp =~ s!\)!)!g; $tmp =~ s!\(!(!g; $tmp =~ s!\|!|!g; $tmp =~ s!([^\&])(\#.*?(=br=))!$1<font color=" +blue"><i>$2</i></font>!g; $tmp =~ s!('.*?('|=br=))!<font color=r +ed>$1</font>!g; $tmp =~ s!(".*?("|=br=))!<font color +=red>$1</font>!g; $tmp =~ s!(return)!<b>$1</b>!g; $tmp =~ s!(require)!<b>$1</b>!g; $tmp =~ s!(while)!<b>$1</b>!g; $tmp =~ s!(foreach)!<b>$1</b>!g; $tmp =~ s!(for)!<b>$1</b>!g; $tmp =~ s!(my)!<b>$1</b>!g; $tmp =~ s!(sub)!<b>$1</b>!g; $tmp =~ s!([^\w])(if)([^\w]*)!$1<b>$2</b>$3!g; $tmp =~ s!(unless)!<b>$1</b>!g; $tmp =~ s!(elsif)!<b>$1</b>!g; $tmp =~ s!(else)!<b>$1</b>!g; $tmp =~ s!(use)!<b>$1</b>!g; $tmp =~ s!(package)!<b>$1</b>!g; $tmp =~ s!<!<!g; $tmp =~ s!>!>!g; $tmp =~ s!"!"!g; $tmp =~ s!"!"!g; #" $tmp =~ s!\s{1};!;!g; #$tmp =~ s!>br>!\n!g; $tmp = "<br><div class=\"codepost\"><font colo +r=\"blue\"><i># $msg{code}</i></font> <br>" . $tmp . '<br><font color="blue"><i># Code En +d</i></font></div>'; }exisog) {} $message =~ s~=br=~<br>~isg;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex - it works, but not the way i want it to =(
by lima1 (Curate) on Sep 17, 2007 at 13:19 UTC | |
by Joost (Canon) on Sep 17, 2007 at 14:12 UTC | |
|
Re: Regex - it works, but not the way i want it to =(
by Anonymous Monk on Sep 17, 2007 at 14:27 UTC | |
|
Re: Regex - it works, but not the way i want it to =(
by SFLEX (Chaplain) on Sep 17, 2007 at 16:35 UTC |