Jump to content


php script wont work..


2 replies to this topic

#1 l3lueMage

    Wanna Be Moderator

  • Publishing Betazoids
  • PipPipPipPip
  • 4,596 posts
  • Gender:Male
  • Location:San Francisco Bay Area

Posted 06 November 2007 - 01:30 PM

<?php
	 $myFile = "alert/alert.txt";
	 $fh = @fopen($myFile, 'r');
if(!feof($fh)) {
	 $theData = fgets($fh);
	 fclose($fh);
?>
<center><div id="alert">
	 <?php echo $theData; ?>
</div></center>
<?php
}
else {
fclose($fh);
}
?>

Its more like the div wont work haha. I want it so if the text file is empty the div and everything doesn't show... :whoosh[1]:

#2 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 06 November 2007 - 03:57 PM

So use a method that returns the contents of the file, not a stream (i hate streams)... :whoosh[1]:
$contents = implode('', file('alert/alert.txt)); // could possible use file_get_contents() also
if(!empty($contents)){
	echo '<div id="alert" align="center">'."\n"
		.$contents."\n</div>";
}
If you want an individual div per line of the file... just remove the implode() statement and make a loop out of the then $contents array.

Edited by rc69, 06 November 2007 - 03:58 PM.


#3 l3lueMage

    Wanna Be Moderator

  • Publishing Betazoids
  • PipPipPipPip
  • 4,596 posts
  • Gender:Male
  • Location:San Francisco Bay Area

Posted 06 November 2007 - 04:56 PM

@_@ There seems to be an error with the echo...D: -sucks at php-

I got it xD

Edited by l3lueMage, 06 November 2007 - 05:44 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users