PHP REQUIRE file input to PHP STRING

I currently have a sort of template file that encompasses text, HTML tags, and <?=PHP expressions?>

I currently use a REQUIRE to effect the "ECHOing"/execution  of it to display it in a web page.

I now need that executed text result in a PHP STRING.

how do i get the text WITH the executed PHP expressions  from the file into a PHP STRING variable?

thanks


willsherwoodAsked:
Who is Participating?
 
Rik-LeggerConnect With a Mentor Commented:
I think you mean output buffering?
http://www.php.net/manual/en/function.ob-get-contents.php

ob_start();
require 'file.php';
$string = ob_get_contents();
ob_end_clean();

Open in new window

0
 
Aaron TomoskySD-WAN SimplifiedCommented:
Like Filegetcontents()?
0
 
willsherwoodAuthor Commented:
but this leaves the PHP expressions unexecuted?
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
Aaron TomoskyConnect With a Mentor SD-WAN SimplifiedCommented:
I'm confused. What is the prolem with require? Require is exactly the same as pasting the contents of the file into your page. What do you need and how does it differ from that?
0
 
willsherwoodAuthor Commented:
i couldn't find how to get this to work     $StringVar = REQUIRE("file.php");
0
 
willsherwoodAuthor Commented:
I'm sorry this is so confusing.
I do not want to display anything.
I would like to get the contents of a file into a string.
I would like the string to be "executed" for any  PHP expressions amongst the text and HTML tags in the file.

File contents example --   file1.php:

<p>Hello <?="W"."orld"?> </p>

[EOF]

and i want to get that into string   $string  so that the string
contains  "<p>Hello World </>"

thanks

0
 
Rik-LeggerCommented:
Ok, so output buffering should do that for you :)

ob_start();
require 'file1.php';
$string = ob_get_contents();
ob_end_clean();

Open in new window

0
 
willsherwoodAuthor Commented:
got it, thanks for your patience.
0
 
willsherwoodAuthor Commented:
thanks all
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.