2013-10-11 7 views
0
for ($i=0; $i<=$lines; $i++) 
{ 
    //get each line and exlplode it.. 
    $part = explode('|', $file[$i]); 

    //now start printing .. 
    echo'<tr> 

      <td width="20%">'.$part[0].'</td> 

      <td width="20%">'.$part[1].'</td> 

      <td width="20%">'.$part[2].'</td> 

      <td width="20%">'.$part[3].'</td> 

      <td width="20%">'.$part[4].'</td> 

     </tr>'; 
} 

Ceci est mon code, il lit pas à partir d'un fichier texte et exploser dans le tableau, mais j'ai un petit problème ici provoque celui-ci doit être lien.colonne Modification du tableau HTML Lien hypertexte

<td width="20%">'.$part[2].'</td> 

.$part[2]. est juste un mot de fichier, mais il a la requête comme www.somesite.com/?q= là à la fin que je dois avoir que

Mot du fichier

ce genre de code n'a pas travailler pour moi <td width="20%"> <a herf='www.somesite.com/?q=''.$part[2].'> '.$part[2].' </a> </td>

J'ai vraiment besoin d'aide avec ce ...

<?php 

//first, get the file... 

$file = file('req.txt'); 



//now count the lines .. 

$lines = count($file); 



//start the table here.. 

echo'<table border="2" width="100%">'; 

echo'<tr> 

       <td width="20%">Naslov</td> 

       <td width="20%">Vrsta</td> 

       <td width="20%">IP</td> 

       <td width="20%">Dodano (DD.MM.YY - HH.MM)</td> 

       <td width="20%">Status</td> 
     </tr>'; 


//start the loop to get all lines in the table.. 

for ($i=0; $i<=$lines; $i++) { 



//get each line and exlplode it.. 

    $part = explode('|', $file[$i]); 

//now start printing .. 

    echo'<tr> 

       <td width="20%">'.$part[0].'</td> 

       <td width="20%">'.$part[1].'</td> 

       <td width="20%">'.$part[2].'</td> 

       <td width="20%">'.$part[3].'</td> 

       <td width="20%">'.$part[4].'</td> 
     </tr>'; 

} 



//close the table so HTML wont suffer :P 

echo'</table>'; 




?> 

Cela devrait produire cela, mais la colonne IP doivent être lien ... Final Product

0

Je pense que vprintf() est votre ami.

<?php 

$fmt = '<tr> 
    <td>%1$s</td> 
    <td>%2$s</td> 
    <td><a href="http://example.com/?q=%3$s">%3$s</a></td> 
    <td>%4$s</td> 
    <td>%5%s</td> 
    </tr>'; 

for ($i=0; $i<=$lines; $i++) 
{ 
    // get each line and explode it.. 
    $part = explode('|', $file[$i]); 

    // now start printing .. 
    vprintf($fmt, $part); 
} 

Et mettre le width="20%" dans votre CSS.

+0

regarder la réponse à nouveau, j'ai posté le script complet et résultat j'ai besoin –

+0

Votre mise à jour change votre question de "comment puis-je faites cela mieux "pour" s'il vous plaît faites fonctionner mon programme ". J'ai répondu à votre question initiale. Vous devriez toujours pouvoir utiliser ma réponse pour améliorer cette section de votre code. – ghoti

Questions connexes