Jump to content

[SOLVED] can I parse current page before outputting?


micah1701

Recommended Posts

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!!!!

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);
?>

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.