J'utilise PHP 5.5.15
, Codeigniter 3 et j'essaie d'enregistrer les données extraites de l'API XML d'Adobe Connect. Tout fonctionne correctement, sauf qu'un élément n'apparaît pas dans l'objet renvoyé par simplexml_load_string
. Cet élément est nommé x-998066622
et provient d'un champ utilisateur personnalisé dans Adobe Connect. D'autres valeurs avec des traits d'union dans le nom de l'élément sont obtenues avec succès. J'ai changé les données dans le xml et l'objet retournés pour protéger la confidentialité.simplexml_load_string ne retourne pas l'élément avec la lettre, le trait d'union et les nombres dans le nom
public function getuserdata(){
$query = $this->adobe_model->get_principals();
echo "Be patient, this one takes a while...<br><br>";
foreach($query->result() as $row){
$url = 'https://uc-d.adobeconnect.com/api/xml?action=principal-info&principal-id='.$row->principal_id.'&session='.$this->session->userdata['breezesession'];
$response = $this->get_response($url);
$xml = simplexml_load_string($response);
if(strtolower($xml->status['code']) == 'ok'){
if(is_object($xml)){
foreach($xml as $key => $value){
$data = array();
if($key == 'principal'){
echo "Updating for ".$value->name."<br><br>";
$data['first_name'] = (string)$value->{'first-name'};
$data['last_name'] = (string)$value->{'last-name'};
$data['company'] = (string)$value->{'x-company'};
$data['cost_center'] = (int)$value->{'cost-center'};
$data['dafis'] = (string)$value->{'x-998066622'};
$data['department'] = (string)$value->{'x-department'};
$data['phone'] = (string)$value->{'x-company-phone'};
$this->adobe_model->update_principal((int)$value['principal-id'],$data);
}
}
}else{
// TO DO: put some error handling here
} // if(is_object($xml))
}else{
$this->login();
} // if(strtolower($xml->status['code']) == 'ok')
}
echo "<strong>Done.</strong><br>";
echo "<a href=\"".site_url()."\">Back To main</a>";
}
Le XML
<?xml version="1.0" encoding="UTF-8"?>
<results>
<status code="ok"/>
<contact>
<email>[email protected]</email>
<first-name>hdfhg</first-name>
<last-name>dghfhfh</last-name>
</contact>
<preferences acl-id="852328317" lang="en" time-zone-id="4"/>
<principal account-id="841422360" disabled="" has-children="false" is-hidden="false" is-primary="false" principal-id="852328317" tos-status="" type="user">
<ext-login>[email protected]</ext-login>
<login>[email protected]</login>
<name>qewrew ewrqwe</name>
<email>[email protected]</email>
<first-name>xcbc</first-name>
<last-name>xbvxcv</last-name>
<x-company>zvcvxzcv</x-company>
<x-company-phone>fgfsgsdfg</x-company-phone>
<x-company-phone-key>sdfgdg</x-company-phone-key>
<x-department>ssgffgdfg</x-department>
<cost-center>sdfgf</cost-center>
<x-998066622>sdfgsfgg</x-998066622>
</principal>
</results>
Vidage des données
object(SimpleXMLElement)#3225 (13) {
["@attributes"]=> array(8) {
["account-id"]=> string(9) "sadfsdf"
["disabled"]=> string(0) ""
["has-children"]=> string(5) "false"
["is-hidden"]=> string(5) "false"
["is-primary"]=> string(5) "false"
["principal-id"]=> string(9) "sdfasdf"
["tos-status"]=> string(0) ""
["type"]=> string(4) "user"
}
["ext-login"]=> string(19) "[email protected]"
["login"]=> string(19) "[email protected]"
["name"]=> string(12) "rerqwe qewrer"
["email"]=> string(19) "[email protected]"
["first-name"]=> string(6) "qerqwrqw"
["last-name"]=> string(5) "qrewrqw"
["x-company"]=> string(3) "qerqwer"
["x-company-phone"]=> string(14) "qwerqwerewq"
["x-company-phone-key"]=> string(10) "wqerwere"
["x-department"]=> string(20) "qwerqwerwer"
["cost-center"]=> string(9) "841779761"
["account-expiry-login-notif"]=> string(5) "false"
}
C'est étrange. Cela fonctionne bien ici en utilisant 5.5.14 ~ https://eval.in/310394. C'est aussi bien sur les versions 5.0.2 - 5.6.7, php7 @ 20140507 - 20150401, hhvm-3.4.1 - 3.6.0 ~ http://3v4l.org/rbEch#v502 – Phil
Peut-être un problème de configuration php? Mon environnement est XAMPP 1.8.3. – earl