8791 sujets

Développement web côté serveur, CMS

Coucou,

voici mon code pour afficher le contenu de fichiers .xml , malheureusement mon script provoque un out of memory, et je ne vois pas d'ou ça vient, pouvez-vous m'aider?


$chemin = '/home/toto/files/';
$dossier = opendir( $chemin );
$exceptions = array( '.', '..' );

while ( $fichier = readdir( $dossier ) )
{
if ( !in_array( $fichier, $exceptions ) AND preg_match( '`.xml$`', $fichier ) == 1 )
{
if ( FALSE !== $informations = @simplexml_load_file($chemin.$fichier)); 

foreach ($informations->localisation as $item) {

if (isset($item->pays) && strlen($item->pays)) {
 echo '<tr><td>'.$item->pays.'</td>';
} else {
 echo '<tr><td>vide</td>';
}

if (isset($item->departement) && strlen($item->departement)) {
 echo '<td>'.$item->departement.'</td>';
} else {
 echo '<td>vide</td>';
}

}

foreach ($informations->presentation as $item) { 

if (isset($item->nom) && strlen($item->nom)) {
 echo '<td>'.$item->nom.'</td>';
} else {
 echo '<td>vide</td>';
}

}

foreach ($informations->annonces as $item) { 

if (isset($item->demande) && strlen($item->demande)) {
 echo '<td>'.$item->demande.'</td>';
} else {
 echo '<td>vide</td>';
}

if (isset($item->offre) && strlen($item->offre)) {
 echo '<td>'.$item->offre.'</td>';
} else {
 echo '<td>vide</td>';
}

}

foreach ($informations->fichier as $item) { 

if (isset($item->modification) && strlen($item->modification)) {
 echo '<td style="font-size: 14px; font-weight: bold; color: #F60000;">'.$item->modification.'</td></tr>';
} else {
 echo '<td style="font-size: 14px;">vide</td></tr>';
}

}

}
}


++
Modifié par csseur666 (11 Aug 2009 - 14:56)
Salut,

// Tu peux virer ça
$exceptions = array( '.', '..' );

// On ne sait jamais
if ($dossier)
{
    while ( $fichier = readdir( $dossier ) )
    {
        // pour les PCRE, le "." signifie "tout",
        // faut l'échapper si tu veux matcher un point
        // Et ajoute le "i" au cas ou le fichier ait une extension XML
        if( preg_match( '`\.xml$`i', $fichier ) )
        {
            if( $informations = @simplexml_load_file($chemin.$fichier) ) // ça suffit largement
            {
Ensuite je ne vois pas trop le problème
Salut Smiley smile

Out Of Memory veut dire ce que ça veut dire, la mémoire alloué à ton script est pleine.

Tu es sur un serveur dédié ou hébergement mutualisé ?