Jump to content

How can I parse and show a page?


OM2

Recommended Posts

I want to remove specific parts of code and show this.

 

How do I do this?

 

I've written some code to do the parsing and get rid of the bits I don't want to show.

 

So far, I have the code:

 

$wholePage = preg_replace("/<!--\s*Admin Code Start\s*-->.*?<!--\s*Admin Code End\s*-->/is", "", $wholePage); 

 

This will get rid of the parts I don't want to show.

 

But... how then do I display the parsed page?

 

Thanks.

 

 

OM

Link to comment
https://forums.phpfreaks.com/topic/107678-how-can-i-parse-and-show-a-page/
Share on other sites

thanks for the reply.

doesn't quite work.

what i've got is:

 

<?php
    $url = "http://" . $_SERVER[ 'HTTP_HOST' ] . urldecode( $_GET[ "u" ] );
    $lines = file( $url );

    $wholePage = "";

$wholePage = preg_replace("/<!--\s*Admin Code Start\s*-->.*?<!--\s*Admin Code End\s*-->/is", "", $wholePage);

print $wholePage;
?>

 

where am i going wrong?

 

thanks.

this should (I hope) do what you are wanting:

<?php
    $url = "http://" . $_SERVER[ 'HTTP_HOST' ] . urldecode( $_GET[ "u" ] );
    $lines = file( $url );
$wholePage = preg_replace("/<!--\s*Admin Code Start\s*-->.*?<!--\s*Admin Code End\s*-->/is", "", $lines);

print $wholePage;
?>

you had $wholePage being parsed, when it's empty. I just changed it so that it now parses $lines

aah... well that doesn't work either.

problem: i was trying to be too clever. :)

i managed to wirte some code to give me the source code of the html output of a php file (minus some bits that i wanted omitted).

this is what i got:

 

<?php
    $url = "http://" . $_SERVER[ 'HTTP_HOST' ] . urldecode( $_GET[ "u" ] );
    $lines = file( $url );
?>
<?php
$wholePage = "";

    foreach( $lines as $line_num => $line ) 
{
	$line = htmlspecialchars( $line );
	$line = str_replace( "<", '<span><', $line );
	$line = str_replace( ">", '></span>', $line );
	$line = str_replace( "<!--", '<em><!--', $line );
	$line = str_replace( "-->", '--></em>', $line );

	$wholePage = $wholePage . $line;
}

$wholePage = preg_replace("/<!--\s*Admin Code Start\s*-->.*?<!--\s*Admin Code End\s*-->/is", "", $wholePage);

echo nl2br($wholePage);
?>

 

now this works fine for its purpose.

but, now, i also need to actually show the html and not just show the source of the html!

 

hope that makes sense.

 

i thought parsing would be 2 or 3 lines of code max?

 

any more thoughts?

thanks.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.