Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder dniwebdesign's Avatar
    Join Date
    Dec 2003
    Location
    Carrot River, Saskatchewan
    Posts
    838
    Thanks
    15
    Thanked 9 Times in 9 Posts

    Reverse the htmlspecialchars

    Now before any of you get ahead of yourselfs... I do not have PHP 5 thus this has to be a PHP 4 answer.
    I encode a chunk of html using htmlspecialchars then split it and break it apart. After that I get out put (in browser) like:
    Code:
    <div class='WARNING'>A LARGE THUNDERSTORM IS DEVELOPING JUST NORTH OF LANIGIN. THIS STORM WILL TRACK EASTWARDS AT 20 KM/H. LARGE HAIL AND DAMAGING GUSTY WINDS CAN BE EXPECTED WITH THIS STORM. THIS IS A WARNING THAT SEVERE THUNDERSTORMS ARE IMMINENT OR OCCURRING IN THESE REGIONS. REMEMBER THAT SOME SEVERE THUNDERSTORMS PRODUCE TORNADOES. LISTEN FOR UPDATED WARNINGS. NOTE..A SUMMARY OF ALL WARNINGS AND WATCHES FOR SOUTHERN SASKATCHEWAN IS AVAILABLE IN THE WWCN13 CWWG BULLETIN ISSUED IMMEDIATELY FOLLOWING THIS BULLETIN.</div><div class='bulletinDiscussion'>THE THUNDERSTORM ACTIVITY OVER SASKATCHEWAN ARE BEGINING TO WEAKEN CONSEQUENTLY TORNADOES ARE NO LONGER EXPECTED. HOWEVER THUNDERSTORMS PRODUCING HAIL AND DAMAGING WINDS ARE STILL POSSIBLE.<br /><br />PLEASE REFER TO THE LATEST PUBLIC FORECASTS FOR FURTHER DETAILS.</div><div class='Update'>ISSUED BY ENVIRONMENT CANADA<br />AT 8:41 PM CST WEDNESDAY 23 AUGUST 2006</div&
    Fine and dandy. Now I want to be able to render the html and put it back in it's original state instead of the "text" version of it, so I can inplement it into a website instead of having all the html text shown. Is this possible?
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    yeh its possible, something like this will work:
    PHP Code:
    $string '';
    $search = array(
    '&gt;',
    '$lt;');
    $replace = array(
    '>',
    '<');
    $string str_replace($search$replace$string); 
    which simply replace the html elements &gt; and &lt; with the real > and < signs

  • #3
    New Coder
    Join Date
    Aug 2006
    Posts
    34
    Thanks
    0
    Thanked 1 Time in 1 Post
    PHP Code:
        function htmlDecode$string )
        {
            
    $transTable get_html_translation_tableHTML_SPECIALCHARSENT_QUOTES );
            if( 
    $transTable["'"] != ''' )
                $transTable["'"] = ''';

            return strtr( $string, array_flip( $transTable ) );
         } 
    Do not specify the ENT_QUOTES if you did not specify that in html_encode.

    Side note: those triple quotes you see there in that if-statement, are not really three single quotes. They're a single quote, followed by & #039;, followed by another single quote. Unfortunately the forum is displaying it as a quote..


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •