Solved

PHP REQUIRE file input to PHP STRING

Posted on 2011-03-20
9
407 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: 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!

 

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

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!

Question has a verified solution.

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

Suggested Solutions

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…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

763 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