string in 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
lordrt
Forum Commoner
Posts: 34
Joined: Sun Jul 19, 2009 11:44 pm

string in a variable

Post by lordrt »

Hello again
I have a PHP statement which goes like this:

$result = fgets($fh);

where $result will store a line read from a text file. I would like to know if the $result var actually contains the strings read, anyone can help?
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: string in a variable

Post by cpetercarter »

fgets() returns 'false' if the operation fails. So you could use a test like

Code: Select all

if ($!result) echo 'An error message';
lordrt
Forum Commoner
Posts: 34
Joined: Sun Jul 19, 2009 11:44 pm

Re: string in a variable

Post by lordrt »

cpetercarter wrote:fgets() returns 'false' if the operation fails. So you could use a test like

Code: Select all

if ($!result) echo 'An error message';
thx will try it
caltoche
Forum Newbie
Posts: 6
Joined: Mon Jul 27, 2009 8:46 am

Re: string in a variable

Post by caltoche »

I think it's (!$, not $!) :

Code: Select all

if (!$result) echo 'An error message';
No ?
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: string in a variable

Post by cpetercarter »

Yes, you are right!
Post Reply