String replace with include file - how to?

Hi All,

I have a basic CMS that saves the data into a MySQL text field. My client wants within one of the pages a contact form so I somehow need to replace a keyword within the content string from the DB with an include file, below is what I have so far but it is just producing 1 each time.

Any idea where I am going wrong?

Thankyou


  // FUNCTION TO REPLACE 
  function code_include($text, $keyword, $file) 
  { 
	 ob_start(); 
	 include($file); 
	 echo $file;
	 $includeText = ob_end_clean(); 
	 return str_replace($keyword, $includeText, $text); 
  } 
  
  // DEFINE STRING FROM DB
  $content_string = stripslashes($content->description);
  
  // DEFINE KEYWORD 
  $thekeyword = 'FORMINSERT'; 
  
  // DEFINE THE FORM
  $registration = $_SERVER['DOCUMENT_ROOT']."/includes/inc_fusion.php"; 
  
  // ECHO THE RESULT OUT 
  echo code_include($content_string, $thekeyword, $registration);


Try this:

ob_start(); 
     include($file); 
     echo $file;
     $includeText = ob_get_contents();
     ob_end_clean(); 

You’re calling ob_end_clean() which just ends the buffer, it returns TRUE which gives you the 1 when echoed.

To end the buffer and retrieve its contents in one step, you can use ob_get_clean() (docs).