我想用PHP讀取一個XML文件,但是我得到這個錯誤,不知道我做錯了什麼。用PHP讀取XML文件
Warning: file_get_contents(username:[email protected]://services.mobile.de/1.0.0/ad/search) [function.file-get-contents]: failed to open stream: No such file or directory in /www/htdocs/*******/mobile.php on line 11
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /www/htdocs/*******/mobile.php:12 Stack trace: #0 /www/htdocs/w00f6d79/mobile.php(12): SimpleXMLElement->__construct('') #1 {main} thrown in /www/htdocs/*******/mobile.php on line 12
我的代碼是:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>mobile.de</title>
</head>
<body>
<?php
$url = "username:[email protected]://services.mobile.de/1.0.0/ad/search";
$xml = file_get_contents($url);
$data = new SimpleXMLElement($xml);
echo $data->children('ad', true)->ad->vehicle->class->children()->children('resource', true)->local-description;
?>
</body>
</html>
URL'用戶名:密碼@ http:// services.mobile.de/1.0.0/ad/search'不可訪問。 – 2015-02-09 12:40:02
'file_get_contents'對creds一無所知。應該使用['curl'函數](http://php.net/manual/en/book.curl.php)。 – mudasobwa 2015-02-09 12:40:15
您的文件爲空 – 2015-02-09 12:40:34