how to read xml file from url using php

后端 未结 5 1125
广开言路
广开言路 2020-12-03 07:02

I have to read an XML file from an URL

$map_url = \"http://maps.google.com/maps/api/directions/xml?origin=\".$merchant_address_url.\"&destination=\".$cus         


        
5条回答
  •  天涯浪人
    2020-12-03 07:17

    Your code seems right, check if you have fopen wrappers enabled (allow_url_fopen = On on php.ini)

    Also, as mentioned by other answers, you should provide a properly encoded URI or encode it using urlencode() function. You should also check if there is any error fetching the XML string and if there is any parsing error, which you can output using libxml_get_errors() as follows:

    message;
           }
       } else {
          print_r($data);
       }
    }
    ?>
    

    If the problem is you can't fetch the XML code maybe it's because you need to include some custom headers in your request, check how to use stream_context_create() to create a custom stream context for use when calling file_get_contents() on example 4 at http://php.net/manual/en/function.file-get-contents.php

提交回复
热议问题