Insert link from CSV
These codes extract data from CSV file and display it as a table
<?php
$lines = file('graphdata/Dimensions.csv');
foreach ($lines as $lineNum => $line) {
if($lineNum == 0) {
continue;
}
print " <tr id=\"tr" . $lineNum . "\">";
$tokens = str_getcsv($line);
print "<td style=\"width: 200px;\">" . trim($tokens[0]) "</td>";
print "<td style=\"width: 100px;\">" . trim($tokens[1]) . "</td>";
print "</script>\n";
}
?>
The first column is actually hyperlinked text and the link itself can appear as a cell in the corresponding row in CSV
Is there a place for the text in the first column to appear as a hyperlink?
thank
+3
source to share
2 answers
General syntax:
echo '<a href="' . $linktTarget . '">' . $linkName . '</a>';
A clearer way to do this is to just play with "and":
edit: Oh, you wanted a whole <td></td>
, to be a link, here you go:
<?php
$lines = file('graphdata/Dimensions.csv');
foreach ($lines as $lineNum => $line) {
if($lineNum == 0) {
continue;
}
print '<tr id="tr' . $lineNum . '">';
$tokens = str_getcsv($line);
print '<td style="width: 200px;"><a href="' . trim($tokens[0]) . '">' . trim($tokens[0]) . '</a></td>';
print '<td style="width: 100px;">' . trim($tokens[1]) . '</td>';
print '</script><br />';
}
?>
Also for what:
print '</script><br />';
at the end?
I found the previous way didn't work in anything other than IE, the simplest way to do it in all browsers is to just add below to your css file:
CSS code:
td a{width:100%;display:block;}
+1
source to share