Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PHP REQUIRE file input to PHP STRING

Posted on 2011-03-20
9
Medium Priority
?
462 Views
Last Modified: 2012-05-11
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
Comment
Question by:willsherwood
  • 5
  • 2
  • 2
9 Comments
 
LVL 39

Expert Comment

by:Aaron Tomosky
ID: 35177571
Like Filegetcontents()?
0
 

Author Comment

by:willsherwood
ID: 35177581
but this leaves the PHP expressions unexecuted?
0
 
LVL 39

Assisted Solution

by:Aaron Tomosky
Aaron Tomosky earned 200 total points
ID: 35177593
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:willsherwood
ID: 35177604
i couldn't find how to get this to work     $StringVar = REQUIRE("file.php");
0
 
LVL 8

Accepted Solution

by:
Rik-Legger earned 1800 total points
ID: 35177606
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
 

Author Comment

by:willsherwood
ID: 35177620
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
 
LVL 8

Expert Comment

by:Rik-Legger
ID: 35177624
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
 

Author Comment

by:willsherwood
ID: 35177804
got it, thanks for your patience.
0
 

Author Closing Comment

by:willsherwood
ID: 35177808
thanks all
0

Featured Post

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question