By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,616 Members | 2,026 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,616 IT Pros & Developers. It's quick & easy.

Reading Data from File HELP!

P: n/a
I'm reading lines from a file to display an image. Each image and
caption is on a new line. I read the string from each line, up until the
line break (\r\n) and then assume my fields are starting again on the
new line. It all works fine, except for the whole thing to work
properly, i need a line break on the last line of the file, causing the
image display to show a broken image... is it possible to ignore a line
if it has nothing in it.. something like an if null statement or
something?????

Here's the bit of the file that spits out the contents of the file...
the file is in format "filename.jpg|caption of file" (without the quotes)

thanks
<?

$data = file($file);

foreach ($f as $o)
{
print "<input type=radio name=line value=$o>";
$g = $o;
list ($q, $a) = explode('|' , trim($g) );
echo "<img src='images/$q' height=100><br><br>";

}

?>
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
matt wrote:
I'm reading lines from a file to display an image. Each image and
caption is on a new line. I read the string from each line, up until the
line break (\r\n) and then assume my fields are starting again on the
new line. It all works fine, except for the whole thing to work
properly, i need a line break on the last line of the file, causing the
image display to show a broken image... is it possible to ignore a line
if it has nothing in it.. something like an if null statement or
something?????

Here's the bit of the file that spits out the contents of the file...
the file is in format "filename.jpg|caption of file" (without the quotes)

thanks
<?

$data = file($file);

foreach ($f as $o)
{
print "<input type=radio name=line value=$o>";
$g = $o;
list ($q, $a) = explode('|' , trim($g) );
echo "<img src='images/$q' height=100><br><br>";

}

?>


If you have an empty line, or a malformed line, one or both of $q and $a
will be empty.

if (isset($q) && isset($a))
{
echo ...
}

NM

--
convert uppercase WORDS to single keystrokes to reply
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.