Reading Data from File HELP!

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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

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)



$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>";


Re: Reading Data from File HELP!

matt wrote:
Quoted text here. Click to load it

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 ...


convert uppercase WORDS to single keystrokes to reply

Site Timeline