oeconom Posted March 17, 2007 Share Posted March 17, 2007 Hi you PHP freaks out there , as I'm really at the beginning of my php experiences I need your help. I assume, it will we a silly question and an easy task for you. What I have: A txt file with data in the following format: 231|"Hyosung"|"GT 125"|"NEU"|"15"||"0"|"schwarz"|"NEUFAHRZEUG"|2990 262|"Hyosung"|"GT 125 R"|"NEU"|"15"||"0"|"rot"|"NEUFAHRZEUG"|3990 ... What I want: Giving out a table with the values in between the " " and a link to a pictue (which has the same name as the first figure in each row plus the file ending .jpg What I already did and/or found (to be reworked if needed ): <table border=1> <tr> <th>Bild</th> <th>Marke</th> <th>Type</th> <th>BJ</th> <th>PS</th> <th>TÜV</th> <th>km</th> <th>Farbe</th> <th>Zubehör/Bemerkungen</th> <th>Preis</th> </tr> <?php $datei = "gebrauchte.TXT"; // Name der Datei $array = file($datei); // Datei in ein Array einlesen for ($i = 0; $i < count($array); $i++) { $array[$i] = explode("|" , $array[$i]); // echo "<tr><th>" . ($i+1) . "</th>"; // Zeilennummer - brauchen wir nicht for ($a = 0; $a < 10; $a++) { // 10 Tabellenspalten if ($a == 0) { echo "<td><a href=\"" . $array[$i][$a] . "\" target=\"_blank\">" . $array[$i][$a] . "</a></td> \n"; } else { echo "<td>" . $array[$i][$a] . "</td> \n"; } } echo "</tr> \n"; } ?> </table> What I still need: -I managed to have the first value being a link, but I still need it to be added the ".jpg", so that the picture is linked and I want the link not to be text, but an icon/picture. -I'd like to have the quotation marks removen (as the txt file is output of another system, I can't change thant format...) -I'd like to have the last value ("Preis") bein formatted as currency --> xx.xxx,xx -Finally, for the optic, I want the table to be online a fine, light-grey dotted grid I'm looking forward to your answers and help, thanks in advance for your advice, FELIX P.S.: I attached the relevant file for your convenience. [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/43116-reading-txt-file-output-as-table/ Share on other sites More sharing options...
ted_chou12 Posted March 17, 2007 Share Posted March 17, 2007 I dont quite understand your code, and have never come across with <th> before, but I believe this might help you: $data = file("gebrauchte.txt"); echo "<table>"; foreach ($data as $line) { $line = str_replace("\"", ""); $info = explode("|", $line); echo "<tr><td>".$info[0]."</td><td>".$info[1]."</td><td>".$info[3]."</td><td>".$info[4]."</td><td>".$info[5]."</td></tr>";} echo "</table>"; For links or images, do something like: echo "<tr><td><a href=\"".$info[0]."\">Link</a></td>..."; echo "<tr><td><img src=\"".$info[0]."\"></td>..."; Ted Link to comment https://forums.phpfreaks.com/topic/43116-reading-txt-file-output-as-table/#findComment-209469 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.