473,385 Members | 1,730 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,385 software developers and data experts.

PHP-CSV echo results display problem

I am using PHP to read a CSV file and print the output to a table. It
works fine but the output is generating an extra empty <td></td> column
at the end of each line and for the life of me I can't find where it's
coming from. I'm sure it's something little but I need help finding it.

I'm using a semi-colon as the delimiter rather than a comma.

Anyone see the problem?

PHP file:
<?php
$filename = "freadtest.txt";
$id = fopen($filename, "r");
while ($data = fgetcsv($id, filesize($filename),";"))
$table[] = $data;
fclose($id);
echo "<table width=\"100%\" border=\"5\">\n";
foreach($table as $row)
{
echo "<tr>";
foreach($row as $data)
echo "<td>$data</td>";
echo "</tr>\n";
}
echo "</table>\n";
?>

freadtest.txt:
John Smith;123 Main Street;Boston, MA 02100;12*@abc.com;
Harry Jones;666 West Central Street;Brooklyn, NY 10026;tr***@who.com;
Perry White;987 Park Drive South;Chicago,IL 60006;fa**@hotmail.com;

Jul 17 '05 #1
3 5688
just a shot in the dark, but maybe becouse there is an end delimeter?

--
Mike Bradley
http://www.gzentools.com -- free online php tools
"JDJones" <se******@sprynet.com> wrote in message
news:4WFRb.128870$Rc4.995323@attbi_s54...
I am using PHP to read a CSV file and print the output to a table. It
works fine but the output is generating an extra empty <td></td> column
at the end of each line and for the life of me I can't find where it's
coming from. I'm sure it's something little but I need help finding it.

I'm using a semi-colon as the delimiter rather than a comma.

Anyone see the problem?

PHP file:
<?php
$filename = "freadtest.txt";
$id = fopen($filename, "r");
while ($data = fgetcsv($id, filesize($filename),";"))
$table[] = $data;
fclose($id);
echo "<table width=\"100%\" border=\"5\">\n";
foreach($table as $row)
{
echo "<tr>";
foreach($row as $data)
echo "<td>$data</td>";
echo "</tr>\n";
}
echo "</table>\n";
?>

freadtest.txt:
John Smith;123 Main Street;Boston, MA 02100;12*@abc.com;
Harry Jones;666 West Central Street;Brooklyn, NY 10026;tr***@who.com;
Perry White;987 Park Drive South;Chicago,IL 60006;fa**@hotmail.com;

Jul 17 '05 #2
>at the end of each line and for the life of me I can't find where it's

I think you may have an empty line at the bottom of
your csv file.
____________________________________
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
DigitallySmooth Inc. | Quick Site Studio
Jul 17 '05 #3
JDJones wrote:
I am using PHP to read a CSV file and print the output to a table. It
works fine but the output is generating an extra empty <td></td> column
at the end of each line and for the life of me I can't find where it's
coming from. I'm sure it's something little but I need help finding it. freadtest.txt:
John Smith;123 Main Street;Boston, MA 02100;12*@abc.com;
Harry Jones;666 West Central Street;Brooklyn, NY 10026;tr***@who.com;
Perry White;987 Park Drive South;Chicago,IL 60006;fa**@hotmail.com;

CountScubula wrote: just a shot in the dark, but maybe becouse there is an end delimeter?


Removing that end semi-colon from the text lines was the answer. It now
displays as it should. I was under the (now mistaken) impression that
the semi-colon was needed at the end of all the fields.

Thank you, Mike. That's why I love this newsgroup. I'm always learning
something new. :)

Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: lawrence | last post by:
I haven't been able to reach www.php.net for days. Most of the rest of the web is working for me, though I've bad trouble reaching any English sites. Anyone else having trouble?
60
by: English Teacher | last post by:
Which would be more useful to learn, PHP or COLDFUSION? I know Coldfusion is popular in the work force. Is PHP? Thanks!
43
by: grz02 | last post by:
Hi, Im an experienced database+software designer and developer, but, unfortunately, anything to do with web-programming and web-systems designs is still a pretty new area to me... (been working...
4
by: nandyal | last post by:
All, The following script works as intended in MS-Windows and in other Linux boxes, except on the one that runs php 4.3.10. Sorry for the long post. 1) # uname -a Linux bubba 2.4.20 #5 SMP...
0
by: 356523600 | last post by:
HTML To PHP Converter 4.2.1.8 Free download Get more for less ... HTML To PHP Converter 4.2.1.8 Get more for less! With a new version of HTML To PHP Converter 4, we've dropped the price and given...
3
by: genenamg | last post by:
Hi, I am trying to run and configure Apache 2.0, php 5 and mysql on win xp professional - this is the first time I have tried to install and configure all three. I am having difficulty trying...
0
by: Benjamin Grieshaber | last post by:
Hi, I´m on SuSE 9.3 with xmlrpc-c and xmlrpc-c-devel installed (ver. 0.9.10) I tried to compile php with xmlrpc support and got the following errors: ...
0
by: Patriot89 | last post by:
I have a quick question in reference to php file extenstions... I have code for example like this... This is all located on this site www.ixalliance.com/BHS/Default (This is my nav.php file) ...
4
by: mechphisto | last post by:
I'm working on a friend's box, Fedora Core 6. It has PHP 5.1.6. I need to install mcrypt into it, and the only way I can find to do it is from source then recompile PHP. So I did all that, and got...
5
Chrisjc
by: Chrisjc | last post by:
Good afternoon, I am seeking some php configuration help. Here is the run down I am running Windows server 2003 and IIS V6.0 I have never had issues before until now. I have Symantec Antivirus 11.0...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.