javifelices

Obtener datos de un xml

Mar 21st, 2019
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.64 KB | None | 0 0
  1. $postdata = http_build_query(
  2.     array(
  3.         'numg' => $numG,
  4.         'nump' => $numP,
  5.         'password' => $pass
  6.     )
  7. );
  8.  
  9. $opts = array(
  10.     'ssl' =>
  11.     array(
  12.         'verify_peer' => false,
  13.         'verify_peer_name' => false,
  14.     ),
  15.     'http' =>
  16.     array(
  17.         'method' => 'POST',
  18.         'header' => 'Content-type: application/x-www-form-urlencoded',
  19.         'content' => $postdata
  20.     )
  21. );
  22.  
  23. $context = stream_context_create($opts);
  24. $contents = file_get_contents($url, false, $context);
  25.  
  26. $xml = simplexml_load_string(html_entity_decode($contents));
  27. if ($xml === false) {
  28.     echo "Error cargando XML\n";
  29.     foreach (libxml_get_errors() as $error) {
  30.         echo "\t", $error->message;
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment