Set a variable to the contents of a file.

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
Majoraslayer
Forum Commoner
Posts: 64
Joined: Thu Jun 30, 2005 11:50 am
Location: In Your Mind...
Contact:

Set a variable to the contents of a file.

Post by Majoraslayer »

How might I set a variable to the contents of a text file? I learned the following doesn't work, though by looking at it I'm sure you'll figure out what I was wanting:

$content_index = include('html/index.html');
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

Code: Select all

$contents = file_get_contents("somefile.txt");
Majoraslayer
Forum Commoner
Posts: 64
Joined: Thu Jun 30, 2005 11:50 am
Location: In Your Mind...
Contact:

Post by Majoraslayer »

...I love you :o
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

Hey Majorslayer, you might want to check out the PHP Manual. No joke! It's one of the best php resources out there. I use it _all_ the time. It'll give you good answers faster than you think. :wink:
Majoraslayer
Forum Commoner
Posts: 64
Joined: Thu Jun 30, 2005 11:50 am
Location: In Your Mind...
Contact:

Post by Majoraslayer »

Yep, fish through 3 million commands when I could just as easily ask some experienced people. I see the logic :wink:
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

Majoraslayer wrote:Yep, fish through 3 million commands when I could just as easily ask some experienced people. I see the logic :wink:
In case its not clear, let me explain it.

First, you don't have to fish through it. The search on php.net's manual is top-notch, even better (because it is so focused) than google in many cases.

Second, the only reason the experienced people *can* answer questions is because users take the time to try to fix the problem, look for answers online, and only when they get truly stumped ask questions. We'd literally never have time if we tried to replace the manual or google.

Not trying to be short or rude, but trust me, you won't get answers for long if you won't take those simple first steps.
Majoraslayer
Forum Commoner
Posts: 64
Joined: Thu Jun 30, 2005 11:50 am
Location: In Your Mind...
Contact:

Post by Majoraslayer »

Roja wrote:
Majoraslayer wrote:Yep, fish through 3 million commands when I could just as easily ask some experienced people. I see the logic :wink:
In case its not clear, let me explain it.

First, you don't have to fish through it. The search on php.net's manual is top-notch, even better (because it is so focused) than google in many cases.

Second, the only reason the experienced people *can* answer questions is because users take the time to try to fix the problem, look for answers online, and only when they get truly stumped ask questions. We'd literally never have time if we tried to replace the manual or google.

Not trying to be short or rude, but trust me, you won't get answers for long if you won't take those simple first steps.
Sorry, didn't mean to offend :oops:

I was just kidding, and I forgot the manual was online >_<.
Post Reply