Jump to content

Reading self, replacing words.


tannerc

Recommended Posts

How can I have a php file, which is included in another page, and reads the page it's pulled into, then replaces any string it finds in that page? Does that make sense? Is this possible with PHP? Is there a better way to go about reading/making the change?

 

      $file = __FILE__;
	$fh = fopen($file, 'r');
	$content = fread($fh, filesize($file)); 
	$content = str_replace('String to replace', 'Whatever replaces it', $content);

 

:facewall:

Link to comment
Share on other sites

The code I posted will be placed in a file, say "magic.php". The magic.php file will then be included in several pages through-out my website. I want the magic.php file to look at the file that it is being pulled into, search it for a string, replace the string, and then show the results.

 

So the problem is: how can I have this script read whatever file it is in, then find a replace part of that file? I know it's possible with javascript, but I wanted to see if there was any way to do it with PHP.

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.