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
https://forums.phpfreaks.com/topic/170112-reading-self-replacing-words/
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.

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.