Re: how to read a file into a variable?
From: J.O. Aho (user_at_example.net)
Date: 11/03/04
- Next message: Jesper Nielsen: "Re: mail() stopped working"
- Previous message: shawn: "Read file and assign value problem."
- In reply to: shawn: "Re: how to read a file into a variable?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 03 Nov 2004 22:48:07 +0100
shawn wrote:
> One more thing:
>
> include will include the file and immediately displays it in the page; I
> want to be able to hold that content and use it elsewhere, such as send it
> out in email.
Everything depends on how you make the include file to look like.
--include file1--
<html><head><title>something</title></head><body>something else</body></html>
--- eof ---
--include file2--
<?PHP
$variable="<html><head><title>something</title></head><body>something
else</body></html>";
?>
--- eof ---
Including the first file would result into that you get the content pasted to
the html page, while the second file would give you a variable which you can
affect as you wish. Keep in mind with the second one, you _CAN'T_ do a
echo $variable;
as that would result in pure HTML code, you would need to do something like
echo eregi_replace(">",">"eregi_replace("<","<",$variable));
This way you will get the output you wanted (there are most likely better ways
to make the replacement of characters).
If you still want to use the first form of include file, then use the function
file():
$array_of_the_whole_file=file('file1.php');
Now you can easilly parse or what ever you want with the file, you can
implode() it too and you get a single variable with the whole content. Check
your php.ini to see how much memory you can use for php, as this will limit
the size of the file you want to read.
//Aho
- Next message: Jesper Nielsen: "Re: mail() stopped working"
- Previous message: shawn: "Read file and assign value problem."
- In reply to: shawn: "Re: how to read a file into a variable?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|