displaying the PHP content as HTML

Discussion in 'PHP' started by zerandib, Feb 25, 2009.

  1. #1
    hello

    i have read a page source using fopen() and get the part of that content in to a variable.
    like this;

    
    $fh = fopen("http://myurl.com", "r");
    $fullstring;
    while(!feof($fh))
    {
        $output = htmlspecialchars(fgets($fh, 1024));
        $fullstring = $fullstring."".$output; 
    }
    
    $section_from_the_source = get_string_between(...................)
    echo $section_from_the_source;
    
    //get_string_between() is user written function.
    //$section_from_the_source [B]contains [/B]<table><tr><td>INFORMATION</td></tr></table>
    
    Code (markup):
    but when i display that variable it just shows this text. NOT the actual table.
    Display as; (Note that i hv read this using fopen)
    <table><tr><td>INFORMATION</td></tr></table>


    if i do something like this, it shows the actual table
    $test_variable = "<table><tr><td>INFORMATION</td></tr></table>";
    echo $test_variable;
    //This Shows the actual table.
    Code (markup):


    Help need to solve this.
     
    zerandib, Feb 25, 2009 IP
  2. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #2
    most probably you need to use htmlentities() decoding function to make it interprete the code as html
     
    crivion, Feb 25, 2009 IP
  3. ActiveFrost

    ActiveFrost Notable Member

    Messages:
    2,072
    Likes Received:
    63
    Best Answers:
    3
    Trophy Points:
    245
    #3
    htmlentities :
    <?php
    $mytext = "<b>This should be in bold</b>";
    echo htmlentities($mytext); // no more bold text .. <b> tags will be printed out as a plain text ..
    ?>
    PHP:
     
    ActiveFrost, Feb 25, 2009 IP
  4. magiatar

    magiatar Active Member

    Messages:
    68
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    73
    #4
    Remove htmlspecialchars on your code and you will have the exact content readed from the url.

    You can look at the source of the html you generated and you can see that the "<" symbol is not printed, instead, it's html representation (I don't remember the exact)

    Is like a space, that is printed like '&nbsp;'

    Don't use the htmlspecialchars and I think your problem is solved.

    Please, reply if this doesn't work :)
     
    magiatar, Feb 25, 2009 IP