473,324 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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|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
1 1508
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: travis ray | last post by:
Hi, I have an extension in which a file object is created in python and passed down to a c extension which attempts to read from it or write to it. Writing to the file pointer seems to work...
1
by: fabrice | last post by:
Hello, I've got trouble reading a text file (event viewer dump) by using the getline() function... After 200 - 300 lines that are read correctly, it suddenly stops reading the rest of the...
3
by: SB | last post by:
Hello. I have an input file which is laid out in the following manner... Name Day 1 am time 1 am time 2 appointment pm time 1 pm time 2 appointment Day 2
20
by: ishmael4 | last post by:
hello everyone! i have a problem with reading from binary file. i was googling and searching, but i just cant understand, why isnt this code working. i could use any help. here's the source code:...
1
by: Magnus | last post by:
allrite folks, got some questions here... 1) LAY-OUT OF REPORTS How is it possible to fundamentaly change the lay-out/form of a report in access? I dont really know it that "difficult", but...
7
by: John Dann | last post by:
I'm trying to read some binary data from a file created by another program. I know the binary file format but can't change or control the format. The binary data is organised such that it should...
9
by: dba123 | last post by:
I need some help and direction on what classes and an example or two (article) on how to read an Excel Worksheet and insert one column into a database table column. I am using .NET 2.0 only. What...
5
blazedaces
by: blazedaces | last post by:
Ok, so you know my problem, java is running out of memory reading with SAX, the event-based xml parser intended more-so than DOM for extremely large files. I'll try to explain what I've been doing...
13
by: swetha | last post by:
HI Every1, I have a problem in reading a binary file. Actually i want a C program which reads in the data from a file which is in binary format and i want to update values in it. The file...
6
by: efrenba | last post by:
Hi, I came from delphi world and now I'm doing my first steps in C++. I'm using C++builder because its ide is like delphi although I'm trying to avoid the vcl. I need to insert new features...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.