Conversión de csv a una tabla HTML que contiene url

The code below converts a .csv table into html: the content of every cell is shown as it is, plain text. However I need to display a linked text in HTML, how can I do?

For example, my csv file has 4 columns as below:

_________________________________________________________________________
|  SITENAME  |          URL        |      PAGENAME    |       URL2       |
--------------------------------------------------------------------------
|  mysite    |http://www.mysite.com|    mynicepage    | http://www.pg.com|
--------------------------------------------------------------------------
|  hersite   |http://www.site.com  |    hernicepage   | http://www.ab.com|
--------------------------------------------------------------------------

The resulting HTML table should have 2 columns: SITENAME and PAGENAME. Each element of these two columns should open the corresponding link (in a new page) appearing in the right side. How to do?

Gracias de antemano.

<?php
$row = 1;
if (($handle = fopen("test.csv", "r")) !== FALSE) {
 while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
    $num = count($data);
    if ($row == 1) {
        echo '<tr>';
    }else{
        echo '<tr>';
    }

    for ($c=0; $c < $num; $c++) {

        if(empty($data[$c])) {
           $value = "&nbsp;";
        }else{
           $value = $data[$c];
        }
        if ($row == 1) {
// ------------- head
            echo '<td style="border-top: 1px solid rgb(111,180,224); border-left: 1px solid rgb(111,180,224); border-bottom: 1px solid rgb(111,180,224);"  align="left" bgcolor="#0066cc" height="36" valign="middle" ><b><font color="#ffffff" size="2">&nbsp;&nbsp;'.$value.'&nbsp;&nbsp;</font></b></td>';
        }else{

// ------------- body
            echo '<td style=" border-bottom: 1px solid rgb(111,180,224);" sdval="9" sdnum="1040;" align="left" bgcolor="#ffffff" height="25"  valign="middle"><font color="#000000" size="2">&nbsp;&nbsp;'.$value.'&nbsp;&nbsp;</font></td>';
        }
    }

    if ($row == 1) {
        echo '</tr>';
    }else{
        echo '</tr>';
    }
    $row++;
}

echo '</tbody></table>';
echo '</center>';   
fclose($handle);
}
?>

preguntado el 23 de abril de 13 a las 13:04

En vez de &nbsp; I would suggest some padding: 0px 5px; en el td. -

1 Respuestas

Verifica si el corriente value is a URL and wrap it with a A HREF tag:

<a href='$value'>$value</a>    

Respondido 23 Abr '13, 19:04

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.