Solved

PHP REQUIRE file input to PHP STRING

Posted on 2011-03-20
9
401 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 50 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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

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 450 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

829 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