FUNCIÓN DE GALERÍA
Código PHP:
<?php
function gal($dire,$w_size,$h_size,$cols)
{
$n_images=0;
$dir=opendir("$dire");
while($file=readdir($dir))
{
if ($file!="." && $file!=".." && $file!="Thumbs.db" && $file!="index.html" && $file!=".htaccess" && $file!="config.dat")
{
$n_images++;
$imagenes[]=$file;
}
}
closedir($dir);
$num_img="".$n_images."";
$num_img_cols="".$cols."";
$num_filas="".ceil($num_img/$num_img_cols)."";
echo '<table width="10%" border="0" cellpadding="3" cellspacing="2" align="center">
<tr>
<td colspan="'.$num_img_cols.'"> </td>
</tr><tr>';
$x=1;
for ($j=0;$j<$n_images;$j++)
{
print "<td align='center'>";
//echo '<img src="'.$dire.'/'.$imagenes[$j].'" width="'.$w_size.'" height="'.$h_size.'">';
print "<a href='".$dire."/".$imagenes[$j]."' class='highslide' onclick=\"return hs.expand(this,{slideshowGroup:'group1',align:'center'})\">";
print '<img src="indexer_resizer.php?ruta_f='.$dire.'/&image='.$imagenes[$j].'&new_width='.$w_size.'&new_height='.$h_size.'" border="0" alt="Pulse para Ampliar" title="Pulse para Ampliar">
</a>';
if ($x%$num_img_cols==0)
{
print "</tr>";
}
$x++;
}
echo "</table>";
}
?>
SCRIPT QUE BUSCA LAS CADENAS ENCERRADAS EN CORCHETES Y SUSTITUYE ESTAS POR EL CONTENIDO DE LA FUNCIÓN GALERÍA SEGÚN LOS DATOS INDICADOS
Código PHP:
<?php
$string = "Hola todos os presento una nueva galeria [galt~imagenes/articulos~100~100~4] Aqui otra más [gal~imagenes/productos~100~100~3]";
$regex = "/\[(.*?)\]/";
preg_match_all($regex, $string, $matches);
for($i=0; $i<count($matches[1]);$i++)
{
$match = $matches[1][$i];
$array = explode('~', $match);
//$newValuet="gal("".$array[1]."","".$array[2]."","".$array[3]."","".$array[4]."")";
$newValue="gal(".$array[1].",".$array[2].",".$array[3].",".$array[4].")";
$string = str_replace($matches[0][$i],$newValue,$string);
}
echo $string;
?>
El problema es que no funciona y se establecen primero las galerías y luego los textos cuando deberían seguir el orden normal de sustitución como con str_replace cuando queremos cambiar un caracter por otro
Ya le he dado mil vueltas a esto y solo me falla esto , rogaría que alguien me pudiese orientar y ver que está mal
Muchas gracias