Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 472
  • Last Modified:

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


0
willsherwood
Asked:
willsherwood
  • 5
  • 2
  • 2
2 Solutions
 
Aaron TomoskyTechnology ConsultantCommented:
Like Filegetcontents()?
0
 
willsherwoodAuthor Commented:
but this leaves the PHP expressions unexecuted?
0
 
Aaron TomoskyTechnology ConsultantCommented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
willsherwoodAuthor Commented:
i couldn't find how to get this to work     $StringVar = REQUIRE("file.php");
0
 
Rik-LeggerCommented:
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
 
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

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 5
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now