in reply to Convert hex to HTML
I suggest you go back to whatever code generated this and fix it.
The text is littered with \u escapes. This escape has zero-length in the resulting string and causes the following character to be uppercased (see ucfirst); however, every following character is a zero which has no case!
While you could search for every occurence of /[0-9a-f]{4}/ (or, even more selectively, /00[3-7][0-9a-f]/) and convert them to characters, you're just as likely to be converting parts of telephone numbers.
You might get away with this but do so at your own risk!:
#!/usr/bin/env perl -l use strict; use warnings; my $text = " \u003cdiv class=\"ja-job-details\"\u003e \u003ch2 " . "class=\"title\"\u003eGlobal Service ..."; print "TEXT: $text"; (my $html = $text) =~ s/(00[3-7][0-9a-f])/pack 'H4', $1/eg; print "HTML: $html";
Output:
TEXT: 003cdiv class="ja-job-details"003e 003ch2 class="title"003eGlob +al Service ... HTML: <div class="ja-job-details"> <h2 class="title">Global Service . +..
-- Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Convert hex to HTML
by Corion (Patriarch) on May 15, 2014 at 07:43 UTC | |
by kcott (Archbishop) on May 15, 2014 at 08:06 UTC |