Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send array from php to html <li>

Tags:

html

php

I need to show arrayList in a html < li > How I send this variable with all the files from php to my html list.

I tryed like this but I don't know whats wrong.. :'(

This is my php code:

$directorioInicial = "./";    //Especifica el directorio a leer
$rep = opendir($directorioInicial);    //Abrimos el directorio

$listaHtml = array();

while ($todosArchivos = readdir($rep)) {  //Leemos el arreglo de archivos     contenidos en el directorio: readdir recibe como parametro el directorio abierto
   if ($todosArchivos != '..' && $todosArchivos != '.' && $todosArchivos != '' && strpos($todosArchivos, '.html') && !is_dir($todosArchivos)) {

    $listaHtml[] = $todosArchivos;       
  }
}

foreach ($listaHtml as $i) {

//    echo $i . "<br>";

}

And this is my html list:

 <div class="propiedadesCaja" id="acordeon">
        <ul>
            <li class="listaPaginas">

                <a class="listado" href="<?php echo $i; ?>" target="probando" ></a>  

            </li>
        </ul>
    </div>

Really Thank you.

like image 375
Lewis Avatar asked Dec 15 '25 12:12

Lewis


1 Answers

Your HTML can look like this:

<div class="propiedadesCaja" id="acordeon">
    <ul>
        <?php foreach($listaHtml as $i){ ?>
        <li class="listaPaginas">
            <a class="listado" href="<?php echo $i; ?>" target="probando">Text here</a>
        </li>
        <?php } ?>
    </ul>
</div>
like image 133
rybo111 Avatar answered Dec 17 '25 01:12

rybo111



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!