Reading Data from File HELP!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • matt

    #1

    Reading Data from File HELP!

    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|c aption 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>";

    }

    ?>
  • News Me

    #2
    Re: Reading Data from File HELP!

    matt wrote:[color=blue]
    > 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|c aption 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>";
    >
    > }
    >
    > ?>[/color]

    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

    Comment

    Working...