[SOLVED] possible to assign content of a file to a variable?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
karlo_ubc
Forum Newbie
Posts: 2
Joined: Mon Dec 22, 2003 7:05 pm

[SOLVED] possible to assign content of a file to a variable?

Post by karlo_ubc »

basically i want to be able to assign the text in a file(.txt or .html) to a variable in another file.
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

Try this...

Code: Select all

<?php

$pathToFile("files/aFile.txt");

ob_start();
readfile($pathToFile);
$contents=ob_get_contents();
ob_end_clean();

// $contents should now contain the contents of the file.

echo $contents;

?>
karlo_ubc
Forum Newbie
Posts: 2
Joined: Mon Dec 22, 2003 7:05 pm

Post by karlo_ubc »

thanks Gen-ik, worked perfect
Post Reply