Re: str_replace an include

From: Date: Tue, 21 Jan 2003 15:37:44 +0000
Subject: Re: str_replace an include
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-132426@lists.php.net to get a copy of this message
Thanks a lot, I think that will be the trick, but I'm still having a bit of a problem. Here's my scenario: class mainReplace{ function feedLinks(){
      ob_start();
      include('links.php');
      $file = ob_get_contents();
      ob_end_clean();
      return $file;
} } $replace = new mainReplace; $read = str_replace('<!--feedLinks--!>', $replace->feedLinks(), $read); print $read; Unfortunately, this is not printing the results of the file include where is should have been replaced. If, however, I say: print $replace->feedLinks() it prints out the results. Any suggestions? Thanks again, Jesse Lawrence J Smith wrote:
I'd recommend looking at the output buffering functions. Something like this would probably work... ob_start(); include("links.php"); $file = ob_get_contents(); ob_end_clean(); The result of parsing and executing links.php will be in $file. Do with it what you will. J Jesse wrote:
Hello all, I'm trying to replace a tag with an include in a template scenario. For example: str_replace("<!--linkTag--!>", include "links.php", $string); This obviously doesn't work, but I'm wondering if anybody knows of a good way to do this. Thanks a bunch, Jesse Lawrence


« previous php.general (#132426) next »