IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

problème avec preg_match pour extraction de données


Sujet :

Langage PHP

  1. #1
    mtq
    mtq est déconnecté
    Membre à l'essai
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    35
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 35
    Points : 14
    Points
    14
    Par défaut problème avec preg_match pour extraction de données
    Bonjour,

    N'etant pas une lumiere en php, que je debute

    Je voudrai parser une page html et plus precisement ceci:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <b>blabla</b><br>&nbsp;<font color="#cccccc">blabla  (nom aleatoire)</font></td><td width="12"></td><td xwidth="326px" colspan="2" xbgcolor="#2A2A2A"><font color="#222222">debug: fid (chiffre aleatoire) - (chiffre aleatoire) survive<br>org: 2220/1274 surv: 1718/1006</font>
    Ensuite je souhaiterai recupere:
    2220/1274/1718/1006 dans des variable differentes bien sur ces chiffres sont aleatoire.

    j'avais essaiser ceci:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    preg_match("<b>blabla<\/b><br>&nbsp;<font color=\"#cccccc\">blabla (.*?)<\/font><\/td><td width=\"12\"><\/td><td xwidth=\"326px\" colspan=\"2\" xbgcolor=\"#2A2A2A\"><font color=\"#222222\">debug: fid (.*?) - (.*?) survive<br>org: (.*?)/(.*?) surv: (.*?)/(.*?)<\/font>",$inhalt,$m)
    $this->att = $m[4];
    $this->def = $m[5];
    $this->att2 = $m[6];
    $this->def2 = $m[7];
    Mais ceci plante et je ne recupere rien.

    Merci

  2. #2
    Inscrit

    Profil pro
    H4X0|2 @ YourLabs Business Service
    Inscrit en
    Octobre 2006
    Messages
    657
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : H4X0|2 @ YourLabs Business Service
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2006
    Messages : 657
    Points : 909
    Points
    909
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    <?php
     $subject = '<b>blabla</b><br>&nbsp;<font color="#cccccc">blabla  (nom aleatoire)</font></td><td width="12"></td><td xwidth="326px" colspan="2" xbgcolor="#2A2A2A"><font color="#222222">debug: fid 4523 - 12344312 survive<br>org: 2220/1274 surv: 1718/1006</font>';
     $pattern = '`<font\scolor="\#cccccc">{1,2}([\w()\s]{0,50})</font></td><td\swidth="12"></td><td\sxwidth="326px"\scolspan="2"\sxbgcolor="\#2A2A2A"><font\scolor="\#222222">debug:\sfid\s([0-9]{1,12})\s-\s([0-9]{1,12})\ssurvive<br>org:\s([0-9]{1,12})/([0-9]{1,12})\ssurv:\s([0-9]{1,12})/([0-9]{1,12})<`um';
     preg_match_all( $pattern, $subject, $matches );
     print_r( $matches );
    ?>
     
    /*
    Sortira :
    Array
    (
        [0] => Array
            (
                [0] => <font color="#cccccc">blabla  (nom aleatoire)</font></td><td width="12"></td><td xwidth="326px" colspan="2" xbgcolor="#2A2A2A"><font color="#222222">debug: fid 4523 - 12344312 survive<br>org: 2220/1274 surv: 1718/1006<
            )
     
        [1] => Array
            (
                [0] => blabla  (nom aleatoire)
            )
     
        [2] => Array
            (
                [0] => 4523
            )
     
        [3] => Array
            (
                [0] => 12344312
            )
     
        [4] => Array
            (
                [0] => 2220
            )
     
        [5] => Array
            (
                [0] => 1274
            )
     
        [6] => Array
            (
                [0] => 1718
            )
     
        [7] => Array
            (
                [0] => 1006
            )
     
    )
     
    */
    3 minutes et du premier coup grace a un testeur de regex. La syntaxe est decrite sur php.net/pcre
    On utilise $this-> dans les classes seulements.
    YourLabs Business Service: Conseil en Strategie Numerique / Club de 1337 Haxors depuis 2012 / Marque de Logiciels Libres / Blog / GitHub /
    Citation Envoyé par C.A.R. Hoare, The 1980 ACM Turing Award Lecture
    There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies.”
    More great quotes - RIP Uriel

  3. #3
    mtq
    mtq est déconnecté
    Membre à l'essai
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    35
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 35
    Points : 14
    Points
    14
    Par défaut
    Citation Envoyé par is_null
    [code]<?php
    3 minutes et du premier coup grace a un testeur de regex. La syntaxe est decrite sur php.net/pcre
    On utilise $this-> dans les classes seulements.
    justement j'utilise $thise -> car je suis dans une classe desoler pour ce manque de si pas presicé :s

    mais ce que tu me donne je vois pas comment je pourrait l'exploiter car tu me donne subject fixe alors que dedans j'ai des chose qui change a chaque fois (variable)

    Il y aurait vraiement pas un truc du genre?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    preg_match("<b>blabla<\/b><br>&nbsp;<font color=\"#cccccc\">blabla (.*?)<\/font><\/td><td width=\"12\"><\/td><td xwidth=\"326px\" colspan=\"2\" xbgcolor=\"#2A2A2A\"><font color=\"#222222\">debug: fid (.*?) - (.*?) survive<br>org: (.*?)/(.*?) surv: (.*?)/(.*?)<\/font>",$inhalt,$m)
    $this->att = $m[4];
    $this->def = $m[5];
    $this->att2 = $m[6];
    $this->def2 = $m[7];
    En tous cas merci de ta reponse

  4. #4
    Inscrit

    Profil pro
    H4X0|2 @ YourLabs Business Service
    Inscrit en
    Octobre 2006
    Messages
    657
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : H4X0|2 @ YourLabs Business Service
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2006
    Messages : 657
    Points : 909
    Points
    909
    Par défaut
    Si tu change les chiifres ou le nom aleatoire, tu verras que ca fonctionne encore.
    Regarde bien la $pattern.
    Il ne faut pas utiliser .* a gogo.
    YourLabs Business Service: Conseil en Strategie Numerique / Club de 1337 Haxors depuis 2012 / Marque de Logiciels Libres / Blog / GitHub /
    Citation Envoyé par C.A.R. Hoare, The 1980 ACM Turing Award Lecture
    There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies.”
    More great quotes - RIP Uriel

  5. #5
    mtq
    mtq est déconnecté
    Membre à l'essai
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    35
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 35
    Points : 14
    Points
    14
    Par défaut
    hum desoler mais la erf debutant.

    demande simple:

    peut tu me fournir le masque pour:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    <b>blabla</b><br>&nbsp;<font color="#cccccc">blabla  (nom aleatoire)</font></td><td width="12"></td><td xwidth="326px" colspan="2" xbgcolor="#2A2A2A"><font color="#222222">debug: fid (chiffre aleatoire) - (chiffre aleatoire) survive<br>org: (2220:chiffre aleatoire)/(1274:chiffre aleatoire) surv: (1718:chiffre aleatoire)/(1006:chiffre aleatoire)</font>
    Sachant que:
    j'ai besoin de sortir 2220/1274/1718/1006 seulement sa dans des variable differente qui sont aleatoire!

    comme marque ds le premier post

    Je te remercie de ta patience enver moi

  6. #6
    Inscrit

    Profil pro
    H4X0|2 @ YourLabs Business Service
    Inscrit en
    Octobre 2006
    Messages
    657
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : H4X0|2 @ YourLabs Business Service
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2006
    Messages : 657
    Points : 909
    Points
    909
    Par défaut
    Est-ce-qu'il faut inclure le "(:chiffre aleatoire)" dans la pattern ? Ou-est-ce que c'est entierement remplacé par un chiffre ou un nombre ?
    YourLabs Business Service: Conseil en Strategie Numerique / Club de 1337 Haxors depuis 2012 / Marque de Logiciels Libres / Blog / GitHub /
    Citation Envoyé par C.A.R. Hoare, The 1980 ACM Turing Award Lecture
    There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies.”
    More great quotes - RIP Uriel

  7. #7
    mtq
    mtq est déconnecté
    Membre à l'essai
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    35
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 35
    Points : 14
    Points
    14
    Par défaut
    je n'ai besoin que de (:chiffre aleatoire) donc oui et remplace par un nombre comme il y a en exemple 2000 ou 4567 etc

    mais au lieu du pattern peut tu juste donner le masque?

    ou mettre les 2

    <br>&nbsp;<font color="#cccccc">De la part de (Aleatoire)</font></td>
    <td width="12"></td>
    <td xwidth="326px" colspan="2" xbgcolor="#2A2A2A"><font color="#222222">debug: fid 88462a2eac19110(Aleatoire) - 2.760(Aleatoire) survive<br>org: 1313705(Aleatoire)/1166265(Aleatoire) surv: 1297477(Aleatoire)/1151588(Aleatoire)</font>

  8. #8
    Membre éclairé Avatar de Korko Fain
    Profil pro
    Étudiant
    Inscrit en
    Août 2005
    Messages
    632
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Août 2005
    Messages : 632
    Points : 718
    Points
    718
    Par défaut
    Essaye avec ça
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ~<b>[^<]*</b><br>&nbsp;<font color="#cccccc">[^<]*</font></td><td width="12"></td><td xwidth="326px" colspan="2" xbgcolor="#2A2A2A"><font color="#222222">debug: fid 4523 - 12344312 survive<br>org: ([0-9]+)/([0-9]+) surv: ([0-9]+)/([0-9]+)</font>~

  9. #9
    mtq
    mtq est déconnecté
    Membre à l'essai
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    35
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 35
    Points : 14
    Points
    14
    Par défaut
    Citation Envoyé par Korko Fain
    Essaye avec ça
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ~<b>[^<]*</b><br>&nbsp;<font color="#cccccc">[^<]*</font></td><td width="12"></td><td xwidth="326px" colspan="2" xbgcolor="#2A2A2A"><font color="#222222">debug: fid 4523 - 12344312 survive<br>org: ([0-9]+)/([0-9]+) surv: ([0-9]+)/([0-9]+)</font>~
    ceci ne fonctionne pas
    Sa en devient desesperant

    preg_match("~<b>[^<]*</b><br>&nbsp;<font color="#cccccc">[^<]*</font></td><td width="12"></td><td xwidth="326px" colspan="2" xbgcolor="#2A2A2A"><font color="#222222">debug: fid [^<]* - [^<]* survive<br>org: ([0-9]+)/([0-9]+) surv: ([0-9]+)/([0-9]+)</font>~", $inhalt, $m )
    $this->att = $m[1];
    $this->def = $m[2];
    $this->att2 = $m[3];
    $this->def2 = $m[4];

  10. #10
    Inscrit

    Profil pro
    H4X0|2 @ YourLabs Business Service
    Inscrit en
    Octobre 2006
    Messages
    657
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : H4X0|2 @ YourLabs Business Service
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2006
    Messages : 657
    Points : 909
    Points
    909
    Par défaut
    La regex que j'ai posté fonctionne : je l'ai essayé.
    Le masque est rangée dans la variable $pattern. Il ne faut pas l'essayer sur un sujet d'exemple avec (nombre aleatoire) mais sur un vrai sujet pour que cela fonctionne.
    YourLabs Business Service: Conseil en Strategie Numerique / Club de 1337 Haxors depuis 2012 / Marque de Logiciels Libres / Blog / GitHub /
    Citation Envoyé par C.A.R. Hoare, The 1980 ACM Turing Award Lecture
    There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies.”
    More great quotes - RIP Uriel

  11. #11
    mtq
    mtq est déconnecté
    Membre à l'essai
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    35
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 35
    Points : 14
    Points
    14
    Par défaut
    Citation Envoyé par is_null
    La regex que j'ai posté fonctionne : je l'ai essayé.
    Le masque est rangée dans la variable $pattern. Il ne faut pas l'essayer sur un sujet d'exemple avec (nombre aleatoire) mais sur un vrai sujet pour que cela fonctionne.
    Justement ceci change a chaque fois donc aleatoire

  12. #12
    Membre éclairé Avatar de Korko Fain
    Profil pro
    Étudiant
    Inscrit en
    Août 2005
    Messages
    632
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Août 2005
    Messages : 632
    Points : 718
    Points
    718
    Par défaut
    Je l'ai testé et pourtant elle fonctionne.
    Donne plutot des exemples à parser et ce qu'il faut récuperer au moins ça sera clair.

  13. #13
    mtq
    mtq est déconnecté
    Membre à l'essai
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    35
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 35
    Points : 14
    Points
    14
    Par défaut
    Je parser une page html entiere
    ensuite je fait differente chose.

    exemple:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    preg_match("/Heure: (\d\d)\.(\d\d)\.(\d\d) (\d\d):(\d\d):(\d\d) heures/",$inhalt,$m);
    $this->zeitpunkt = mktime($m[4],$m[5],$m[6],$m[2],$m[1],$m[3]);
    Cela me permet ensuite quand j'enregistre la page parser de refaire une url en y mettant date et heure

    Pour des petit preg_match sa va mais la c'est un gros :s et je bloque

    Ps: les saut de ligne influence?

    Voici la source tels quel:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    <td xwidth="327px" colspan="2" bgcolor="#2a2a2a" height="35">&nbsp;<b>Flotte d'attaque</b>
    <br>&nbsp;<font color="#cccccc">De la part de NomAttaquant</font></td>
    <td width="12"></td>
    <td xwidth="326px" colspan="2" xbgcolor="#2A2A2A"><font color="#222222">debug: fid 46464d80af7463c - 15 survive<br>org: 375/300 surv: 375/300</font></td>
    NomAttaquant= aleatoire
    46464d80af7463c = aleatoire
    15 survive = 15 aleatoire
    org: 375/300 surv: 375/300 = les chiffre sont aleatoire et c'est ceci que je souhaite recupere

  14. #14
    Inscrit

    Profil pro
    H4X0|2 @ YourLabs Business Service
    Inscrit en
    Octobre 2006
    Messages
    657
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : H4X0|2 @ YourLabs Business Service
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2006
    Messages : 657
    Points : 909
    Points
    909
    Par défaut
    Citation Envoyé par mtq
    Justement ceci change a chaque fois donc aleatoire
    Pour le sujet :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    <br>&nbsp;<font color="#cccccc">De la part de (Aleatoire)</font></td>
    <td width="12"></td>
    <td xwidth="326px" colspan="2" xbgcolor="#2A2A2A"><font color="#222222">debug: fid 18462a2eac19110 - 1.760 survive<br>org: 1313705/1166265 surv: 1297477/1151588</font>
    <br>&nbsp;<font color="#cccccc">De la part de (Aleatoire2)</font></td>
    <td width="12"></td>
    <td xwidth="326px" colspan="2" xbgcolor="#2A2A2A"><font color="#222222">debug: fid 23462a2eac19110 - 2.460 survive<br>org: 2313705/2166265 surv: 2297477/2151588</font>
    Voila ca que j'ai :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    Array
    (
        [0] => Array
            (
                [0] => Array
                    (
                        [0] => <font color="#cccccc">De la part de (Aleatoire)</font></td>
                        [1] => (Aleatoire)
                    )
     
                [1] => Array
                    (
                        [0] => <font color="#cccccc">De la part de (Aleatoire2)</font></td>
                        [1] => (Aleatoire2)
                    )
     
            )
     
        [1] => Array
            (
                [0] => Array
                    (
                        [0] => <td xwidth="326px" colspan="2" xbgcolor="#2A2A2A"><font color="#222222">debug: fid 18462a2eac19110 - 1.760 survive<br>org: 1313705/1166265 surv: 1297477/1151588<
                        [1] => 18462a2eac19110
                        [2] => 1.760
                        [3] => 1313705
                        [4] => 1166265
                        [5] => 1297477
                        [6] => 1151588
                    )
     
                [1] => Array
                    (
                        [0] => <td xwidth="326px" colspan="2" xbgcolor="#2A2A2A"><font color="#222222">debug: fid 23462a2eac19110 - 2.460 survive<br>org: 2313705/2166265 surv: 2297477/2151588<
                        [1] => 23462a2eac19110
                        [2] => 2.460
                        [3] => 2313705
                        [4] => 2166265
                        [5] => 2297477
                        [6] => 2151588
                    )
     
            )
     
    )
    Avec le code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    <?
    ob_start();
    ?>
    <br>&nbsp;<font color="#cccccc">De la part de (Aleatoire)</font></td>
    <td width="12"></td>
    <td xwidth="326px" colspan="2" xbgcolor="#2A2A2A"><font color="#222222">debug: fid 18462a2eac19110 - 1.760 survive<br>org: 1313705/1166265 surv: 1297477/1151588</font>
    <br>&nbsp;<font color="#cccccc">De la part de (Aleatoire2)</font></td>
    <td width="12"></td>
    <td xwidth="326px" colspan="2" xbgcolor="#2A2A2A"><font color="#222222">debug: fid 23462a2eac19110 - 2.460 survive<br>org: 2313705/2166265 surv: 2297477/2151588</font>
    <?php
     $sujet = ob_get_clean();
     $masque1 = '`<font\scolor="\#cccccc">De la part de {1,2}([\w()\s]{0,50})</font></td>`m';
     $masque2 = '`^<td xwidth="326px" colspan="2" xbgcolor="\#2A2A2A"><font color="\#222222">debug: fid ([0-9a-z]{1,35}) - ([\d\.]{1,12}) survive<br>org: ([0-9]{1,12})/([0-9]{1,12}) surv: ([0-9]{1,12})/([0-9]{1,12})<`m';
     preg_match_all ( $masque1, $sujet, $matches[], PREG_SET_ORDER );
     preg_match_all ( $masque2, $sujet, $matches[], PREG_SET_ORDER  );
     print_r( $matches );
    ?>
    Malheureusement je ne peux rien faire pour vous si vous n'essayez pas ce code.
    YourLabs Business Service: Conseil en Strategie Numerique / Club de 1337 Haxors depuis 2012 / Marque de Logiciels Libres / Blog / GitHub /
    Citation Envoyé par C.A.R. Hoare, The 1980 ACM Turing Award Lecture
    There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies.”
    More great quotes - RIP Uriel

  15. #15
    Membre éclairé Avatar de Korko Fain
    Profil pro
    Étudiant
    Inscrit en
    Août 2005
    Messages
    632
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Août 2005
    Messages : 632
    Points : 718
    Points
    718
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ~<b>[^<]*</b><br>&nbsp;<font color="#cccccc">[^<]*</font></td><td width="12"></td><td xwidth="326px" colspan="2" xbgcolor="#2A2A2A"><font color="#222222">debug: fid [0-9a-z]+ - [0-9a-z]+ survive<br>org: ([0-9]+)/([0-9]+) surv: ([0-9]+)/([0-9]+)</font>~
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <td xwidth="327px" colspan="2" bgcolor="#2a2a2a" height="35">&nbsp;<b>Flotte d'attaque</b><br>&nbsp;<font color="#cccccc">De la part de NomAttaquant</font></td><td width="12"></td><td xwidth="326px" colspan="2" xbgcolor="#2A2A2A"><font color="#222222">debug: fid 46464d80af7463c - 15 survive<br>org: 375/300 surv: 375/300</font></td>
    1 => 375
    2 => 300
    3 => 375
    4 => 300

  16. #16
    mtq
    mtq est déconnecté
    Membre à l'essai
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    35
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 35
    Points : 14
    Points
    14
    Par défaut
    Citation Envoyé par Korko Fain
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ~<b>[^<]*</b><br>&nbsp;<font color="#cccccc">[^<]*</font></td><td width="12"></td><td xwidth="326px" colspan="2" xbgcolor="#2A2A2A"><font color="#222222">debug: fid [0-9a-z]+ - [0-9a-z]+ survive<br>org: ([0-9]+)/([0-9]+) surv: ([0-9]+)/([0-9]+)</font>~
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <td xwidth="327px" colspan="2" bgcolor="#2a2a2a" height="35">&nbsp;<b>Flotte d'attaque</b><br>&nbsp;<font color="#cccccc">De la part de NomAttaquant</font></td><td width="12"></td><td xwidth="326px" colspan="2" xbgcolor="#2A2A2A"><font color="#222222">debug: fid 46464d80af7463c - 15 survive<br>org: 375/300 surv: 375/300</font></td>
    1 => 375
    2 => 300
    3 => 375
    4 => 300
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    preg_match('~<b>Flotte d\'attaque</b><br>&nbsp;<font color="#cccccc">[^<]*</font></td><td width="12"></td><td xwidth="326px" colspan="2" xbgcolor="#2A2A2A"><font color="#222222">debug: fid [0-9a-z]+ - [0-9a-z]+ survive<br>org: ([0-9]+)/([0-9]+) surv: ([0-9]+)/([0-9]+)</font>~',$inhalt,$m);
    $this->att = $m[1];
    $this->def = $m[2];
    $this->att2 = $m[3];
    $this->def2 = $m[4];
    Lorsque la page passe a la "moulinette" je met un echo pour voir si $att esr rempli mais rien se passe

  17. #17
    Inscrit

    Profil pro
    H4X0|2 @ YourLabs Business Service
    Inscrit en
    Octobre 2006
    Messages
    657
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : H4X0|2 @ YourLabs Business Service
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2006
    Messages : 657
    Points : 909
    Points
    909
    Par défaut
    Citation Envoyé par mtq
    Lorsque la page passe a la "moulinette" je met un echo pour voir si $att esr rempli mais rien se passe
    Normal puisque la regex que vous utilisez n'est pas prête pour le décimal avant survive; contrairement à celle que j'ai posté.
    Il faut changer "[0-9a-z]+ surviv" en "[0-9\.]+ surviv" pour que l'autre regex proposée fonctionne
    YourLabs Business Service: Conseil en Strategie Numerique / Club de 1337 Haxors depuis 2012 / Marque de Logiciels Libres / Blog / GitHub /
    Citation Envoyé par C.A.R. Hoare, The 1980 ACM Turing Award Lecture
    There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies.”
    More great quotes - RIP Uriel

  18. #18
    Membre éclairé Avatar de Korko Fain
    Profil pro
    Étudiant
    Inscrit en
    Août 2005
    Messages
    632
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Août 2005
    Messages : 632
    Points : 718
    Points
    718
    Par défaut
    Il faut absolument éviter le '.' qui sont tres gourmand. Il faut toujours préferer les classes.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ~<b>[^<]*</b><br>&nbsp;<font color="#cccccc">[^<]*</font></td><td width="12"></td><td xwidth="326px" colspan="2" xbgcolor="#2A2A2A"><font color="#222222">debug: fid [0-9a-z]+ - [0-9a-z.]+ survive<br>org: ([0-9]+)/([0-9]+) surv: ([0-9]+)/([0-9]+)</font>~

  19. #19
    mtq
    mtq est déconnecté
    Membre à l'essai
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    35
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 35
    Points : 14
    Points
    14
    Par défaut
    Citation Envoyé par Korko Fain
    Il faut absolument éviter le '.' qui sont tres gourmand. Il faut toujours préferer les classes.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ~<b>[^<]*</b><br>&nbsp;<font color="#cccccc">[^<]*</font></td><td width="12"></td><td xwidth="326px" colspan="2" xbgcolor="#2A2A2A"><font color="#222222">debug: fid [0-9a-z]+ - [0-9a-z.]+ survive<br>org: ([0-9]+)/([0-9]+) surv: ([0-9]+)/([0-9]+)</font>~
    Ce que tu me met ne marche pas

  20. #20
    Membre éclairé Avatar de Korko Fain
    Profil pro
    Étudiant
    Inscrit en
    Août 2005
    Messages
    632
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Août 2005
    Messages : 632
    Points : 718
    Points
    718
    Par défaut
    Et si tu cherchai plus simplement
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    #org: ([0-9]+)/([0-9]+) surv: ([0-9]+)/([0-9]+)#
    Ce serait pas plus simple ?

    Voir avec un preg_match_all
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    #(?<=(org)|(surv): )([0-9]+)/([0-9]+)#

+ Répondre à la discussion
Cette discussion est résolue.
Page 1 sur 2 12 DernièreDernière

Discussions similaires

  1. Réponses: 16
    Dernier message: 13/12/2015, 12h50
  2. Tableau pour extraction de données avec split
    Par guenaw-83 dans le forum Collection et Stream
    Réponses: 1
    Dernier message: 03/02/2013, 00h13
  3. problème avec strtok pour récupérer les vides
    Par manikou dans le forum MFC
    Réponses: 4
    Dernier message: 02/06/2005, 20h08
  4. Réponses: 5
    Dernier message: 27/08/2003, 11h45

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo