OM2 Posted May 28, 2008 Share Posted May 28, 2008 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 More sharing options...
jonsjava Posted May 28, 2008 Share Posted May 28, 2008 do you mean this: $wholePage = preg_replace("/<!--\s*Admin Code Start\s*-->.*?<!--\s*Admin Code End\s*-->/is", "", $wholePage); print $wholePage; ? I'm betting that's not what you meant. Link to comment https://forums.phpfreaks.com/topic/107678-how-can-i-parse-and-show-a-page/#findComment-551982 Share on other sites More sharing options...
OM2 Posted May 28, 2008 Author Share Posted May 28, 2008 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. Link to comment https://forums.phpfreaks.com/topic/107678-how-can-i-parse-and-show-a-page/#findComment-551990 Share on other sites More sharing options...
jonsjava Posted May 28, 2008 Share Posted May 28, 2008 so, you're saying that your variable ($wholePage) is empty? I don't see where you populate it with data. Link to comment https://forums.phpfreaks.com/topic/107678-how-can-i-parse-and-show-a-page/#findComment-551994 Share on other sites More sharing options...
OM2 Posted May 28, 2008 Author Share Posted May 28, 2008 yes: i'm not getting anything. have i got these 2 lines correct: $url = "http://" . $_SERVER[ 'HTTP_HOST' ] . urldecode( $_GET[ "u" ] ); $lines = file( $url ); this is code from other code i used. let me know. thanks. Link to comment https://forums.phpfreaks.com/topic/107678-how-can-i-parse-and-show-a-page/#findComment-552015 Share on other sites More sharing options...
jonsjava Posted May 28, 2008 Share Posted May 28, 2008 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 Link to comment https://forums.phpfreaks.com/topic/107678-how-can-i-parse-and-show-a-page/#findComment-552023 Share on other sites More sharing options...
OM2 Posted May 28, 2008 Author Share Posted May 28, 2008 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. Link to comment https://forums.phpfreaks.com/topic/107678-how-can-i-parse-and-show-a-page/#findComment-552042 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.