Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I have a text which is actually in hex which I would like to convert into HTML. Please can you help me out.

" \u003cdiv class=\"ja-job-details\"\u003e \u003ch2 class=\"title\"\u003eGlobal Service Delivery Manager\u003c/h2\u003e \u003cdiv class=\"meta\"\u003e \u003cul class=\"classifications\"\u003e \u003cli data-id=\"11711\"\u003e Executive \u003c/li\u003e \u003cli data-id=\"11713\"\u003e Sydney \u003c/li\u003e \u003cli data-id=\"11714\"\u003e Permanent / Full Time \u003c/li\u003e \u003c/ul\u003e \u003cp class=\"date-posted\"\u003e 13/5/2014 \u003c/p\u003e \u003c/div\u003e \u003cdiv class=\"description\"\u003e Global position managing teams in Australia, Asia, EMEA and The Americas\u003cbr\u003e Full responsibility for Service Delivery for a company in hyper growth\u003cbr\u003e Open plan, modern offices in the Rocks\u003cbr\u003e \u003cbr\u003e \u003cstrong\u003eSiteMinder\u003c/strong\u003e leads the hotel distribution technology space, constantly challenging the status quo to provide innovative cloud-based products that allow hotels to connect with their customers. Our exceptional product suite and client support ensure that we are the partner of choice for over 12,000 hoteliers worldwide.\u0026nbsp;\u003cbr\u003e \u0026nbsp;\u0026nbsp;\u003cbr\u003e We continue to grow exponentially with nearly 250 employees in offices across Sydney, Bangkok, Cape Town, Dallas and London, and a plan to double in size again after securing a $30 million dollar Silicon Valley investment.\u0026nbsp;\u003cbr\u003e \u0026nbsp;\u003cbr\u003e \u003cstrong\u003eWhat we have available: \u003c/strong\u003e\u003cbr\u003e \u003cstrong\u003e\u003c/strong\u003e\u0026nbsp;\u003cbr\u003e The Global Service Delivery Manager (GSDM) will build and drive successful service delivery teams across our global offices.\u0026nbsp; \u003cbr\u003e \u0026nbsp;\u003cbr\u003e You will provide clear direction on business processes related to support and implementation and work with the Team Leaders to ensure KPI\u0027s and SLA\u0027s are set up and measured, with ongoing reviews of targets.\u0026nbsp;\u0026nbsp; This will involve tracking and analysing service performance for each customer, region and product. \u003cbr\u003e \u0026nbsp;\u003cbr\u003e The GSDM will conduct regular performance reviews with Service Managers and Team Leaders to report on progress and performance of the team and In collaboration with Service Managers and Team Leaders, be responsible for their professional development and training through SiteMinder performance reviews, career management, mentoring, disciplinary procedures and team morale. \u003cbr\u003e \u0026nbsp;\u003cbr\u003e The implementation of workflow policies \u0026amp; procedures and development of the service strategy to meet the business requirements, will also form part of this role. \u003cbr\u003e \u0026nbsp;\u003cbr\u003e \u003cstrong\u003eWhat you bring to the table:\u003c/strong\u003e\u003cbr\u003e \u0026nbsp;\u003cbr\u003e \u003cul\u003e \u003cli\u003eProven IT Service Management knowledge and experience working at global level\u003c/li\u003e \u003cli\u003eITIL implementation\u0026nbsp;and/or\u0026nbsp;ITIL\u0026nbsp;process improvement experience \u003c/li\u003e \u003cli\u003eExperience leading globally dispersed teams\u0026nbsp;\u003c/li\u003e \u003cli\u003eDemonstrated effective Management and Communication Skills\u003c/li\u003e \u003cli\u003eHands on ability and knowledge of CRM systems and customer service platforms\u003c/li\u003e \u003cli\u003eThe ability to analyse data to accurately measure and report on performance.\u003c/li\u003e \u003cli\u003eExperience with resource planning and budgetary preparation is essential\u003c/li\u003e \u003c/ul\u003e Desirable skills:\u003cbr\u003e \u003cul\u003e \u003cli\u003eKnowledge and/or understanding of Follow-the-Sun methodologies\u003c/li\u003e \u003cli\u003eExperience with cloud based customer service platforms, ideally Zendesk\u003c/li\u003e \u003c/ul\u003e To hear more about this opportunity apply now for a confidential discussion or contact me directly on deirdre.rice@siteminder.com \u003c/div\u003e \u003cdiv class=\"apply\"\u003e \u003ca class=\"back-link\" href=\"#\" title=\"Back to search results\"\u003eBack to search results\u003c/a\u003e \u003cinput type=\"button\" class=\"ja-button\" data-job-id=\"1554909\" value=\"Apply Now\" title=\"Apply Now\" /\u003e \u003c/div\u003e \u003c/div\u003e "

Thanks

Replies are listed 'Best First'.
Re: Convert hex to HTML
by kcott (Archbishop) on May 15, 2014 at 07:30 UTC

    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

      If you think of the text as text in a text file, instead of text in Perl source code, then the \uXXXX escapes would suggest Javascript Unicode escapes, which are usually comprised of four letters.

      Adapting your regex to such text would then yield the same result as your other approach though.

      But as we lack further information, it's kinda hard to determine what was really meant.

        Yes, you could well be right about that.

        #!/usr/bin/env perl -l use strict; use warnings; use JSON; my $text = '{"html":" \u003cdiv class=\"ja-job-details\"\u003e \u003ch +2 ' . 'class=\"title\"\u003eGlobal Service ..."}'; print decode_json($text)->{html};

        Output:

        <div class="ja-job-details"> <h2 class="title">Global Service ...

        -- Ken

Re: Convert hex to HTML
by Anonymous Monk on May 15, 2014 at 06:58 UTC
    Thats called json

    also resembles spam

      I am pretty sure JSON requires an object/array wrapper. A nude Javascript string is not valid JSON.

      perl -MJSON::XS -le 'decode_json(q{\u003cdiv class=\"ja-job-details... +})' malformed JSON string, neither tag, array, object, number, string or a +tom, at character offset 0 (before "\\u003cdiv class=\\"...") at -e l +ine 1.