Jump to content

Recommended Posts

This must be a stupid question, but what is the code to read a textfile and store it into a variable? Example:

I have a text file called "number.txt" with the number "9" in it.

I have another file called "index.php" that is in the same directory. Using PHP, I want to be able to declare a variable for example "$thenumber" that is equal to whatever number is in the number.txt file.

Please help!
[code]$thenumber=file('number.txt');[/code]


That should do the job mate.. puts it into an array.. to read it back you would have to use somthing like this.

[code]
foreach($thenumber as $number) {
echo $number.'<Br>';
}
[/code]

If you only have 1 line then i beleave it is stored in the variable instead of an array.

Regards
Liam
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.