Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PHP REQUIRE file input to PHP STRING

Posted on 2011-03-20
9
Medium Priority
?
447 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 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
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…
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 count occurrences of each item in an array.

715 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