Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-24-2006, 05:11 AM   PM User | #1
dniwebdesign
Regular Coder

 
dniwebdesign's Avatar
 
Join Date: Dec 2003
Location: Carrot River, Saskatchewan
Posts: 838
Thanks: 15
Thanked 9 Times in 9 Posts
dniwebdesign is an unknown quantity at this point
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
dniwebdesign is offline   Reply With Quote
Old 08-24-2006, 07:43 AM   PM User | #2
Mwnciau
Regular Coder

 
Join Date: May 2006
Location: Wales
Posts: 820
Thanks: 1
Thanked 82 Times in 79 Posts
Mwnciau is on a distinguished road
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
Mwnciau is offline   Reply With Quote
Old 08-25-2006, 05:59 AM   PM User | #3
Nimlhûg
New Coder

 
Join Date: Aug 2006
Posts: 34
Thanks: 0
Thanked 1 Time in 1 Post
Nimlhûg is an unknown quantity at this point
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..
Nimlhûg is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:29 AM.


Advertisement
Log in to turn off these ads.