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

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.