Function to view HTML source of a dynamic generated content php page??

Discussion in 'PHP' started by 123GoToAndPlay, Jul 5, 2010.

  1. #1
    Hi,

    I have created a simple newsletter form with a couple of text/img fields. All data is stored in a mysql db. I also created a preview function which just gets the right data based on the newsletter_id and uses a template.

    Now i need to create a view html source function. I have tried this but i doesn't work
    
    function getHTML(){
    	ob_start();
    $newsletter_id = 3;
    	include('preview.php');
    	$currentoutput = ob_get_clean();
    	return $currentoutput;
    }
    $content = getHTML();
    echo $content;
    
    Code (markup):
    But directing the browser to preview.php?newsletter_id=3 shows the newsletter ok

    Any advice, tips
     
    123GoToAndPlay, Jul 5, 2010 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    You will probable have to run a preg_replace on the $content ie: replace < with &lt; and > with &gt;

    and then echo the content like this

    
    <pre>
    <?php
    print_r ($content);
    ?>
    </pre>
    
    PHP:
    You may or may not need the <pre> tags, try it first ?


    EDIT:
    Try this:
    
    function pre($var) {
    $replace = array('<' => '&lt;', '>' => '&gt;');
    return strtr($var, $replace);
    }
    echo pre($content);
    
    PHP:
    You will most likely also need to replace quotes " and & so just add to the array
     
    Last edited: Jul 6, 2010
    MyVodaFone, Jul 6, 2010 IP