php newbie - just need to fix my html and insert hyperlink

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cdWebGirl
Forum Newbie
Posts: 1
Joined: Sun Jun 21, 2009 12:57 pm

php newbie - just need to fix my html and insert hyperlink

Post by cdWebGirl »

I am pulling data to create a simple HTML page from a csv file in php. I managed to find a script to do this (I do not know php), but I can't figure out how to customize it to my needs. All I need is to correct the HTML (it is inserting an extra <td> tag) and to simply link the business name with the website address (some may not have website) - also I do not want to show the website address to save space. Can anyone take a look?

<?php
$filename = "test2.csv";

/*
No cache!!
*/
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// always modified
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
/*
End of No cache
*/

function viewlog($filename) {
$fp = fopen($filename,"r");
$file = fread($fp,65535);
$replaced = eregi_replace(",", "</td><td>", $file);
$replaced2 = eregi_replace("\n", "</tr><tr><td>", $replaced);
$replaced3 = eregi_replace("\r", "", $replaced2);
fclose($fp);

return $replaced3;
}
echo "<html><head><title>CSV File Viewer</title></head><body>";
// Start the table definition of your choice
echo "<table cellspacing=0 cellpadding=5 width=100% style='font-size:9pt;font-family:arial'><tr><td>";

echo viewlog($filename);
echo "</table></body></html>";
exit;
?>


Sample data:

Business Name Address City Phone Website
GRAPHICUS COMMUNICATIONS 16 Pine St Millville 856-825-4516 http://www.graphicuscommunications.com
QUALITY PRINTING 1181 E Landis Ave Vineland 856-691-7577 http://www.qualityprintingnj.com
ANIMAL HOSPITAL OF MILLVILLE 60 Sharp Street Millville 856-825-3434
MILLVILLE TIRE 1510 Wheaton Avenue Millville 856-327-8646
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: php newbie - just need to fix my html and insert hyperlink

Post by Eric! »

reposted your code so it can be read (see instuctions on how to post code)

Code: Select all

<?php
$filename = "test2.csv";
 
/*
No cache!!
*/
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// always modified
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
/*
End of No cache
*/
 
function viewlog($filename) {
$fp = fopen($filename,"r");
$file = fread($fp,65535);
$replaced = eregi_replace(",", "</td><td>", $file);
$replaced2 = eregi_replace("\n", "</tr><tr><td>", $replaced);
$replaced3 = eregi_replace("\r", "", $replaced2);
fclose($fp);
 
return $replaced3;
}
echo "<html><head><title>CSV File Viewer</title></head><body>";
// Start the table definition of your choice
echo "<table cellspacing=0 cellpadding=5 width=100% style='font-size:9pt;font-family:arial'><tr><td>";
 
echo viewlog($filename);
echo "</table></body></html>";
exit;
?>
t
It appears there are a number of confusing html tag lines. It starts with <tr><td> on line 29. Then the function starts replacing commas with </tr><td> This doesn't seem right, however you need to post the html source that is output for me to see the formatting errors. I don't have the mental capacity to run all these replacements in my head to figure out what isn't right. At least not on a weekend.
Post Reply