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 :

xml+caractère & pose problème à php


Sujet :

Langage PHP

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2009
    Messages
    16
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2009
    Messages : 16
    Points : 10
    Points
    10
    Par défaut xml+caractère & pose problème à php
    Bonjour, ou rebonjour pour ceux qui ont lu mon précédent post.

    J'ai un petit soucis sur la lecture de mon fichier xml par php.

    J'utilise la méthode :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    if (file_exists('PlanningInfos/PlanningInfos.xml')) {
    		$xml = simplexml_load_file('PlanningInfos/PlanningInfos.xml');
    		//attribue le noued du stage en cours dans la variable $content
    		$content = $xml->$categ->stages[$stage];
    		//récupère la partie nombre du tarif pour éviter 'euros'"
    		$tarif = strpos($content['tarif']," ");
    		$tarif = substr($content['tarif'], 0, $tarif);		
    	}
    pour lire mon xml.

    Jusque là, aucun problème (grâce à ce forum).

    Mon soucis est que dans mon xml, qui est lu par flash et par php sur 2 pages différentes, j'ai besoin d'indiquer l'adresse à utiliser pour flash qui se compose comme ceci:

    http://127.0.0.1/site/index.php?page...glais1&stage=0

    or, quand j'insère cette adresse dans mon xml dans un attribut en tant que string :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <stages titre="Stage FCL 1.028 (IFR-VFR)" date="Du 12/01 au 16/01." heures="30 Heures." programme="Ecoute, phrases d'urgence, vols fictifs." lieu="Toulouse" places="8 places" tarif="620 euros" type="1028" urlParams="page=paiement&type=anglais&categ=anglais1&stage=0"/>
    PHP plante et m'affiche:
    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
    Warning: simplexml_load_file() [function.simplexml-load-file]: PlanningInfos/PlanningInfos.xml:8: parser error : EntityRef: expecting ';' in C:\Program Files\EasyPHP 2.0b1\www\site\php\pages\paiement.php on line 11
     
    Warning: simplexml_load_file() [function.simplexml-load-file]: e" places="8 places" tarif="620 euros" type="1028" urlParams="page=paiement&type in C:\Program Files\EasyPHP 2.0b1\www\site\php\pages\paiement.php on line 11
     
    Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in C:\Program Files\EasyPHP 2.0b1\www\site\php\pages\paiement.php on line 11
     
    Warning: simplexml_load_file() [function.simplexml-load-file]: PlanningInfos/PlanningInfos.xml:8: parser error : EntityRef: expecting ';' in C:\Program Files\EasyPHP 2.0b1\www\site\php\pages\paiement.php on line 11
     
    Warning: simplexml_load_file() [function.simplexml-load-file]: laces" tarif="620 euros" type="1028" urlParams="page=paiement&type=anglais&categ in C:\Program Files\EasyPHP 2.0b1\www\site\php\pages\paiement.php on line 11
     
    Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in C:\Program Files\EasyPHP 2.0b1\www\site\php\pages\paiement.php on line 11
     
    Warning: simplexml_load_file() [function.simplexml-load-file]: PlanningInfos/PlanningInfos.xml:8: parser error : EntityRef: expecting ';' in C:\Program Files\EasyPHP 2.0b1\www\site\php\pages\paiement.php on line 11
     
    Warning: simplexml_load_file() [function.simplexml-load-file]: 20 euros" type="1028" urlParams="page=paiement&type=anglais&categ=anglais1&stage in C:\Program Files\EasyPHP 2.0b1\www\site\php\pages\paiement.php on line 11
     
    Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in C:\Program Files\EasyPHP 2.0b1\www\site\php\pages\paiement.php on line 11
    J'ai compris qu'il s'agit du caractère & qui n'est pas accepté.
    Pouvez-vous m'aider ?

    merci.

  2. #2
    Membre émérite Avatar de darkstar123456
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mars 2008
    Messages
    1 896
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Mars 2008
    Messages : 1 896
    Points : 2 838
    Points
    2 838
    Par défaut
    str_replace("&", "&amp;" $str);

  3. #3
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2009
    Messages
    16
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2009
    Messages : 16
    Points : 10
    Points
    10
    Par défaut
    re,

    merci d'étudier mon problème, pour autant voici l'erreur qui s'affiche :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Parse error: parse error, unexpected T_VARIABLE in C:\Program Files\EasyPHP 2.0b1\www\site\php\pages\paiement.php on line 12
    avez-vous une autre piste svp ?

  4. #4
    Membre émérite Avatar de darkstar123456
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mars 2008
    Messages
    1 896
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Mars 2008
    Messages : 1 896
    Points : 2 838
    Points
    2 838
    Par défaut
    Tu pourrais donner le code de ta page paiement.php stp ?

  5. #5
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2009
    Messages
    16
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2009
    Messages : 16
    Points : 10
    Points
    10
    Par défaut
    Re,

    voici le code de ma page php:

    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
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    <?php
    	//type d'url : http://127.0.0.1/site/index.php?page=paiement&type=anglais&categ=anglais1&stage=0
    	//récupération de la catégorie
    	$categ=$_GET['categ'];
     
    	//récupération du stage
    	$stage=$_GET['stage'];
    	$stage=intval($stage);
     
        if (file_exists('PlanningInfos/PlanningInfos.xml')) {
    		$xml = simplexml_load_file('PlanningInfos/PlanningInfos.xml');
    		str_replace("&", "&amp;" $xml);
    		//attribue le noued du stage en cours dans la variable $content
    		$content = $xml->$categ->stages[$stage];
    		//récupère la partie nombre du tarif pour éviter 'euros'"
    		$tarif = strpos($content['tarif']," ");
    		$tarif = substr($content['tarif'], 0, $tarif);		
    	} else {
    		exit("Echec lors de l'ouverture du fichier Xml.");
    	}
     
    	//Génération du numéro de commande aléatoire
    	$PBX_CMD = date("hiymd");
    ?>
     
    <div class="page">
            <div class="titlePage">
    		<?php if($_GET['type']=="anglais"){echo $titre_Page_Anglais_Paiement;}else{echo $titre_Page_Prepas_Paiement;}?>
            </div>
            <br/>
            <ul class="ariane">
                <li class="active"><?php echo $tab_1_Paiment; ?></li>
                <li class="inactive"><a href="index.php?page=prepas_icna"><?php echo $tab_2_Paiment; ?></a></li>
            </ul>
            <div style="height:315px; overflow:auto; padding-right:25px;">
                <div class="interligne" >
                    <ul>
                        <li><strong><?php echo $titre_Formation_Paiement ?></strong></li>
                        <span><?php echo $content_1_Paiment." : "; ?></span><span class="formPaiement"><?php echo $content['titre']; ?></span><br/>
                        <span><?php echo $content_2_Paiment." : "; ?></span><span class="formPaiement"><?php ?></span><br/>
                        <span><?php echo $content_3_Paiment." : "; ?></span><span class="formPaiement"><?php echo $content['date']; ?></span><br/>
                        <span><?php echo $content_4_Paiment." : "; ?></span><span class="formPaiement"><?php echo $content['heures']; ?></span><br/>
                        <span><?php echo $content_5_Paiment." : "; ?></span><span class="formPaiement"><?php echo $content['programme']; ?></span><br/>
                        <span><?php echo $content_6_Paiment." : "; ?></span><span class="formPaiement"><?php echo $content['lieu']; ?></span><br/>
                        <span><?php echo $content_7_Paiment." : "; ?></span><span class="formPaiement"><?php echo $content['places']; ?></span><br/>
                        <span><?php echo $content_8_Paiment." : "; ?></span><span class="formPaiement"><?php echo $content['tarif']; ?></span><br/>
                        <span><?php echo $content_9_Paiment." : "; ?></span><span class="formPaiement"><?php ?></span>
                    </ul>
                </div>
                <div class="interligne">
                	<ul>
                        <li><strong><?php echo $titre_Participant_Paiement ?></strong></li>
                        <FORM ACTION = cgi-bin/modulev2.cgi METHOD = post>
                            <INPUT TYPE = hidden NAME = PBX_MODE VALUE = 1 />
                            <INPUT TYPE = hidden NAME = PBX_SITE VALUE = XXXXXX /> 
                            <INPUT TYPE = hidden NAME = PBX_RANG VALUE = 98 /> 
                            <INPUT TYPE = hidden NAME = PBX_IDENTIFIANT VALUE = 3 />
                            <INPUT TYPE = hidden NAME = PBX_TOTAL VALUE = <?php echo $tarif."00"; ?> /> 
                            <INPUT TYPE = hidden NAME = PBX_DEVISE VALUE = 978 /> 
                            <INPUT TYPE = hidden NAME = PBX_CMD VALUE = <?php echo $PBX_CMD?> />
                            <INPUT TYPE = hidden NAME = PBX_RETOUR VALUE = ref:R; /> 
                            <INPUT TYPE = hidden NAME = PBX_EFFECTUE VALUE = merci /> 
                            <INPUT TYPE = hidden NAME = PBX_REFUSE VALUE = refus /> 
                            <INPUT TYPE = hidden NAME = PBX_ANNULE VALUE = refus />
     
                            <!-- Variables pour paypal 
                            <form target="paypal" action="https://www.paypal.com/fr/cgi-bin/webscr" method="post">
                            !-->
     
                            <input type=hidden name=cmd value=_xclick/>
                            <input type=hidden name=business value=seller@designerfotos.com/>
                            <input type=hidden name=item_name value=hat/>
                            <input type=hidden name=item_number value=<?php echo $PBX_CMD?>/>
                            <input type=hidden name=amount value=<?php echo $tarif.".00"; ?>/>
                           	<input name=currency_code type=hidden value="EUR" />
     
                            <p><?php echo $content_Nom_paiement." : "; ?><span style="margin-left: 40px;"><INPUT TYPE = "text" NAME = NOM VALUE = ""></span></p>
                            <p><?php echo $content_Prenom_paiement." : "; ?><span style="margin-left: 40px;"><INPUT TYPE = "text" NAME = PRENOM VALUE = ""></span></p>
                            <p><?php echo $content_Adresse_paiement." : "; ?><span style="margin-left: 40px;"><INPUT TYPE = "text" NAME = ADRESSE VALUE = ""></span></p>
                            <p><?php echo $content_Telephone_paiement." : "; ?><span style="margin-left: 40px;"><INPUT TYPE = "text" NAME = TEL VALUE = ""></span></p>
                            <p><?php echo $content_Mail_paiement." : "; ?><span style="margin-left: 40px;"><INPUT TYPE = "text" NAME = PBX_PORTEUR VALUE = ""></span></p>
                            <p><?php if($_GET['type']=="prepas"){echo $content_Ecole_paiement;}?></p>  
                            <p>
    							<?php echo $content_Type_paiement." : "; ?>
                                <INPUT TYPE = "radio" NAME = TYPE VALUE = EPL ><?php echo $content_Epl_paiement; ?></INPUT>
                                <INPUT TYPE = "radio" NAME = TYPE VALUE = ICNA ><?php echo $content_Icna_paiement; ?></INPUT>
                                <INPUT TYPE = "radio" NAME = TYPE VALUE = EPLICNA ><?php echo $content_Epl_Icna_paiement; ?></INPUT>
                                <INPUT TYPE = "radio" NAME = TYPE VALUE = AUTRE ><?php echo $content_Autre_paiement; ?></INPUT>
                            </p>
                            <p>
    							<?php echo $content_Moyen_paiement." : "; ?>
                                	<INPUT TYPE = "radio" NAME = PAY VALUE = PAYPAL ><img src="https://www.paypal.com/fr_FR/FR/i/logo/PayPal_mark_50x34.gif" /></INPUT>                       
                                	<INPUT TYPE = "radio" NAME = PAY VALUE = CB ><img src="imgs/etransactions.png" /></INPUT>
                            </p>
                            <p><INPUT type="checkbox" NAME = VALID value="OKCGE" /><?php echo $content_Cge_Paiement; ?></p>
                            <p align="center"><INPUT TYPE = submit NAME = bouton_paiement VALUE = Paiement /></p>
     
                        </FORM>
                    </ul>          
                </div>
          </div>
    </div>
    merci...

  6. #6
    Membre averti
    Profil pro
    Inscrit en
    Août 2005
    Messages
    483
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 483
    Points : 309
    Points
    309
    Par défaut
    Bonjour,

    Il s'agit juste d'une idées pour ton stockage xml :

    au lieu de ne mettre qu'une seule propriété urlParams, pourquoi ne pas stocker chaque couple argument=valeur dans une propriété différente:

    Arg1="page=paiement" Arg2="type=anglais" Arg3="categ=anglais1" Arg4="stage=0".

    Et tu rajoute les & à la construction du lien.

    Il ne s'agit que d'une idée . Maintenant je ne sais pas si tu auras un nombre de paramètre GET variable.

    ++

  7. #7
    Membre émérite Avatar de darkstar123456
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mars 2008
    Messages
    1 896
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Mars 2008
    Messages : 1 896
    Points : 2 838
    Points
    2 838
    Par défaut
    Erreur ligne 12, désolé j'viens de voir que c'est moi qui ai fait la faute à la base dans ma réponse : il manque une virgule

    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    // str_replace("&", "&amp;" $xml);
    // à remplacer par :
    str_replace("&", "&amp;", $xml);

    Par contre, je ne suis pas sur qu'on puisse faire un str_replace() directement dans la variable $xml... à tester

  8. #8
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2009
    Messages
    16
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2009
    Messages : 16
    Points : 10
    Points
    10
    Par défaut
    re,

    désolé, j'ai le même type d'erreur.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Warning: simplexml_load_file() [function.simplexml-load-file]: PlanningInfos/PlanningInfos.xml:8: parser error : EntityRef: expecting ';' in C:\Program Files\EasyPHP 2.0b1\www\site\php\pages\paiement.php on line 11
     
    Warning: simplexml_load_file() [function.simplexml-load-file]: "8 places" tarif="620 euros" type="1028" urlParams="index.php?page=paiement&type in C:\Program Files\EasyPHP 2.0b1\www\site\php\pages\paiement.php on line 11
    Je crois réellement que c'est dès la lecture qu'il y a un problème, vu que quand j'enlève ton code, ça me fait les mêmes erreurs en ne métant que ça:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    if (file_exists('PlanningInfos/PlanningInfos.xml')) {
    		$xml = simplexml_load_file('PlanningInfos/PlanningInfos.xml');	
    	} else {
    		exit("Echec lors de l'ouverture du fichier Xml.");
    	}
    dans mon xml j'ai mis:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <stages urlParams="index.php?page=paiement&type=anglais&categ=anglais1&stage=0"/>
    il y a t'il une autre possibilité ?

    merci encore pour ton aide.

  9. #9
    Membre émérite Avatar de darkstar123456
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mars 2008
    Messages
    1 896
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Mars 2008
    Messages : 1 896
    Points : 2 838
    Points
    2 838
    Par défaut
    en réalité, c'est à la création du fichier XML qu'il faut écrire ' &amp; ' à la place de ' & '

  10. #10
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2009
    Messages
    16
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2009
    Messages : 16
    Points : 10
    Points
    10
    Par défaut
    ok c'est bon ça marche nickel, merci beaucoup.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [ODBC] Problème php caractère spéciaux
    Par drogba72 dans le forum PHP & Base de données
    Réponses: 13
    Dernier message: 27/02/2009, 16h51
  2. PHP+XML = Simple Xml qui pose problème
    Par Ryuuku dans le forum Langage
    Réponses: 3
    Dernier message: 12/02/2009, 19h45
  3. caractère \ pose problème
    Par questionneuse dans le forum SQL Procédural
    Réponses: 2
    Dernier message: 11/07/2006, 16h25

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