Probleme en php
Résolu
perrinos
Messages postés
2
Date d'inscription
Statut
Membre
Dernière intervention
-
perrinos Messages postés 2 Date d'inscription Statut Membre Dernière intervention -
perrinos Messages postés 2 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
j'ai un probleme avec ce code, ma premiere boucle while ne fait qu'une seule itération alors qu'elle devrait en faire plusieurs car pos_ligne_1 et pos_ligne2 ne sont pas nul apres une iteration.
Pouvez vous m'aider?
Merci
$url="http://localhost/Copie_de_ex_extraction/ex.html";
$html = get_html($url);
$pos1 = strpos($html, "<tbody>");
$pos2 = strpos($html,"</tbody>",$pos1);
$data_brut = substr($html,$pos1,$pos2-$pos1);//garde que ce qu'il ya entre <tbody>
$pos_ligne_1 = strpos($data_brut, "<tr>"); //position du premier <tr>
$pos_ligne_2 = strpos($data_brut, "</tr>",$pos_ligne_1);//position de la fin du premier </tr>
while ($pos_ligne_1&pos_ligne_2) {//tant qu'il y a des tr donc des données a extraire
//on récupère ce qu'il y a entre le premier <tr>
$ligne=substr($data_brut,$pos_ligne_1,$pos_ligne_2-$pos_ligne_1);
$pos_attribut1=strpos($ligne, "<td>");
$pos_attribut2=strpos($ligne, "</td>",$pos_attribut1);
while($pos_attribut1 & $pos_attribut2) {
$attribut=substr($ligne,$pos_attribut1,$pos_attribut2-$pos_attribut1);//garde ce qu'il y a dans le premier td
echo strip_tags($attribut);//on affiche l'attribut obtenu en enlevant avec strip_tags les balises html
echo "<br>\n";
$pos_attribut1=strpos($ligne, "<td>",$pos_attribut2);
$pos_attribut2=strpos($ligne, "</td>",$pos_attribut1);
}
$pos_ligne_1 = strpos($data_brut, "<tr>",$pos_ligne_2);
$pos_ligne_2 = strpos($data_brut, "</tr>",$pos_ligne_1);
}
j'ai un probleme avec ce code, ma premiere boucle while ne fait qu'une seule itération alors qu'elle devrait en faire plusieurs car pos_ligne_1 et pos_ligne2 ne sont pas nul apres une iteration.
Pouvez vous m'aider?
Merci
$url="http://localhost/Copie_de_ex_extraction/ex.html";
$html = get_html($url);
$pos1 = strpos($html, "<tbody>");
$pos2 = strpos($html,"</tbody>",$pos1);
$data_brut = substr($html,$pos1,$pos2-$pos1);//garde que ce qu'il ya entre <tbody>
$pos_ligne_1 = strpos($data_brut, "<tr>"); //position du premier <tr>
$pos_ligne_2 = strpos($data_brut, "</tr>",$pos_ligne_1);//position de la fin du premier </tr>
while ($pos_ligne_1&pos_ligne_2) {//tant qu'il y a des tr donc des données a extraire
//on récupère ce qu'il y a entre le premier <tr>
$ligne=substr($data_brut,$pos_ligne_1,$pos_ligne_2-$pos_ligne_1);
$pos_attribut1=strpos($ligne, "<td>");
$pos_attribut2=strpos($ligne, "</td>",$pos_attribut1);
while($pos_attribut1 & $pos_attribut2) {
$attribut=substr($ligne,$pos_attribut1,$pos_attribut2-$pos_attribut1);//garde ce qu'il y a dans le premier td
echo strip_tags($attribut);//on affiche l'attribut obtenu en enlevant avec strip_tags les balises html
echo "<br>\n";
$pos_attribut1=strpos($ligne, "<td>",$pos_attribut2);
$pos_attribut2=strpos($ligne, "</td>",$pos_attribut1);
}
$pos_ligne_1 = strpos($data_brut, "<tr>",$pos_ligne_2);
$pos_ligne_2 = strpos($data_brut, "</tr>",$pos_ligne_1);
}
A voir également:
- Probleme en php
- Easy php - Télécharger - Divers Web & Internet
- Expert php pinterest - Télécharger - Langages
- Retour a la ligne php - Forum Webmastering
- Alert php - Forum PHP
- Retour a la ligne php ✓ - Forum PHP