micah1701 Posted April 14, 2008 Share Posted April 14, 2008 I have a page with a lot of html and I want to run it through a set of regular expression to swap out some data. I've done that much before (using fopen to read the contents of the page into a script that runs the regex and then resaves the data back to the file) but this time, I don't want to save changes. I just want to make those changes at runtime but leave the file otherwise alone. Example. Say I have a page full of html and, when the page displays, I want every period to be an exclamation mark. is it possible to put a snippet of code at the top and-or bottom of that page to parse then data and send it to the user's browsers with the changes I want? I don't think its possible but my brains a little foggy on this monday so I thought I'd ask. basically I want to have a page like: <?php // here is some function w/ my regex parameters ?> <html><body> here is my page. with line after line of html code. blah balh blah.... <code> etc... </body></html> and the users would see: here is my page! with line after line of html code! blah balh blah!!!! Link to comment https://forums.phpfreaks.com/topic/101100-solved-can-i-parse-current-page-before-outputting/ Share on other sites More sharing options...
Zhadus Posted April 14, 2008 Share Posted April 14, 2008 Could save it into a new file and redirect them to the new page so the original page is preserved. Link to comment https://forums.phpfreaks.com/topic/101100-solved-can-i-parse-current-page-before-outputting/#findComment-517046 Share on other sites More sharing options...
rhodesa Posted April 14, 2008 Share Posted April 14, 2008 Something like this should do it: <?php ob_start(); ?> <html><body> here is my page. with line after line of html code. blah balh blah.... <code> etc... </body></html> <?php $contents = ob_end_clean(); print str_replace('.','!',$contents); ?> Link to comment https://forums.phpfreaks.com/topic/101100-solved-can-i-parse-current-page-before-outputting/#findComment-517049 Share on other sites More sharing options...
micah1701 Posted April 14, 2008 Author Share Posted April 14, 2008 ah! I totally forgot about buffering. My brain does not work on Mondays. Thanks so much! I'll mess around with that :-D Link to comment https://forums.phpfreaks.com/topic/101100-solved-can-i-parse-current-page-before-outputting/#findComment-517054 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.