473,385 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to process a local file rather than just read it

I can read a local file with

fopen("myFile.php");

However this gives me the source of the file (i.e. php code). I want
to get the results of the file after it has been evaluated (i.e. HTML).
The obvious way of doing this is

include 'myfile.php';

However, I want to process the evaluated result. For example:

echo htmlentities( include 'myfile.php' );

This doesn't work because the result of the include statement is true
or false rather than a string.

I'm sure this is very simple, but I'm just learning.

- Jeff -

Oct 28 '05 #1
5 1718
Use include() to parse the file and capture the output with output
buffering. For instance:

ob_start();
include 'myfile.php';
$output = ob_get_contents();
ob_end_clean(); //discard the buffer since we already have the contents

echo htmlentities($output);

Oct 28 '05 #2
Wow. That was entirely non-intuitive. I would have thought there was
some php-evaluate() function I was overlooking.

Works great, though. Thanks!

- Jeff -

Oct 28 '05 #3
NC
as*******@gmail.com wrote:

Wow. That was entirely non-intuitive. I would have thought
there was some php-evaluate() function I was overlooking.


There is: http://www.php.net/eval

But include() works much faster.

Cheers,
NC

Oct 28 '05 #4
I suppose/think you could load it with fopen etc as you describe and
then use eval($file_contents)... but that would be silly

Oct 28 '05 #5
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

as*******@gmail.com wrote:
I would have thought there was
some php-evaluate() function I was overlooking.


You can do it that way too. Have a look at http://php.net/eval .

- --
- ----------------------------------
Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

Un ordenador no es un televisor ni un microondas, es una herramienta
compleja.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFDYoNx3jcQ2mg3Pc8RAlLlAJ9tO8uc8XcuYedfQ+EBa4 ZqlZ9fZACff++6
jEEaFzMStjD6FJdyaBsOja8=
=4Or1
-----END PGP SIGNATURE-----
Oct 28 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Peter Ĺstrand | last post by:
There's a new PEP available: PEP 324: popen5 - New POSIX process module A copy is included below. Comments are appreciated. ---- PEP: 324 Title: popen5 - New POSIX process module
3
by: Mart Rogers | last post by:
We have a situation where we have decided (in an attempt to keep things simple) to stick to local assemblies rather than global ones. However we now have the following situation looming AssyA ...
5
by: Joseph | last post by:
Hello, I have a C# program that builds a txt file and then, calls an external exe (this external exe simply imports this txt file into a DBF (DBase) file. (we copy a template of the DBF file into...
18
by: jas | last post by:
Hi, I would like to start a new process and be able to read/write from/to it. I have tried things like... import subprocess as sp p = sp.Popen("cmd.exe", stdout=sp.PIPE)...
3
by: BCM | last post by:
In a simple console app the following few lines open up an Acrobat file without a hitch: Process p = new Process(); p.StartInfo.FileName = @"C:\test.pdf"; p.Start(); But the same code in an...
11
by: Tim Marsden | last post by:
Hi, I have a routine which is call from a ASP.NET web form. This routine creates an excel application, opens a workbook , runs some code to update the workbook, saves it as HTML on the sever and...
3
by: JeffM | last post by:
I have a .dat file on a remote server that seems to be locked. I have tried to FTP to it and delete it, rename it, copy over it and I get the error. "Could not copy temporary files to the output...
3
by: Loane Sharp | last post by:
Hi there I use the FileStream object to download a zip file over the internet to my local disk. The file downloads successfully, but when I attempt to unzip it, I'm told that the file is in use...
13
by: George | last post by:
Hi, I am re-writing part of my application using C#. This application starts another process which execute a "legacy" program. This legacy program writes to a log file and before it ends, it...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.