我正在尝试使用PHP下载网页的内容.当我发出命令时:
$f = file_get_contents("http://mobile.mybustracker.co.uk/mobile.php?searchMode=2");
Run Code Online (Sandbox Code Playgroud)
它返回一个报告服务器已关闭的页面.然而,当我将相同的URL粘贴到我的浏览器中时,我得到了预期的页面.
有谁知道是什么导致了这个?file_get_contents是否会传输任何区别于浏览器请求的标头?
以下PHP代码完全符合我的要求.问题是我需要在Perl中重新创建它并且我一直在使用open()和sysopen()Perl函数,但不能这样做.有没有人有任何帮助或知道任何可能有帮助的链接?谢谢.
$URL = "http://example.com/api.php?arguments=values";
echo file_get_contents($URL);
Run Code Online (Sandbox Code Playgroud) 我在下面的这段代码在我的远程托管服务器上工作正常,但由于某种原因在我的本地linux机器上工作.我也尝试过使用file_get_contents获取restful服务,但它也返回false.
有谁知道为什么会这样?
谢谢 :)
$xml_data = simplexml_load_file("****");
if ($xml == FALSE)
{
echo "Failed loading XML\n";
foreach (libxml_get_errors() as $error)
{
echo "\t", $error->message;
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个问题,即使我将空格替换为%20并将此内容作为终极URL,浏览器将"%20"变为"%2520"
这是我的代码,任何建议让这个工作?这似乎很容易,但我卡住了:/
<?php
//$_GET['song'] will contain a song name with spaces
$song = str_replace(array("%20", "&", "?" , "/"), array(" ", "", "", ""), $_GET['song']);
// I use this to check how the GET 'song' looks after the str_replace
$list = "http://www.lyrdb.com/lookup.php?q=" . $song . "&for=fullt";
echo "list url is " . $list . "<hr>";
$content = file_get_contents("http://www.lyrdb.com/lookup.php?q=" . str_replace(" ", "%20", $song) . "&for=fullt");
echo $content;
?>
Run Code Online (Sandbox Code Playgroud)
如果你去http://webservices.lyrdb.com/lookup.php?q=red%20hot%20chili%20peppers&for=fullt结果应该输出一个歌词代码列表.
当我去我的网站/?song =红辣椒时,它也将空格转换为%20,但如果看起来浏览器将%'转换为%25.
有人可以帮我吗?
我是Golang的新手.其实我是PHP开发人员.
我需要file_get_contentsGolang中的功能.
您可以根据我的要求为此提供代码或建议Golang库.
注意:请记住file-get-contents,不仅仅是"读取文件".
我将此代码放入一个函数(php类)中:
$theFile = '/test/test.xml'; // these are in the public folder
dd(file_get_contents($theFile));
Run Code Online (Sandbox Code Playgroud)
如果我去mydomain.local/test/test.xml,我会得到有效的 xml 代码。
但是file_get_contents,我收到此错误:
file_get_contents(/test/test.xml): failed to open stream: No such file or directory
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题?
我正在尝试创建一个应用程序来上传个人资料图片,但我遇到了问题.
if (isset($_POST['uploadprofileimg'])) {
$image = base64_encode(file_get_contents($_FILES['profileimg']['tmp_name']));
$options = array('http' => array(
'method' => "POST",
'header' => "Authorization: Bearer sdf541gs6df51gsd1bsb16etb16teg1etr1ge61g\n",
"Content-Type: application/x-www-form-urlencoded",
'content' => $image
));
$context = stream_context_create($options);
$imgurURL = "https://api.imgur.com/3/image";
$response = file_get_contents($imgurURL, FALSE, $context);
}
Run Code Online (Sandbox Code Playgroud)
我收到了这个通知:
注意:file_get_contents():未指定Content-type假设在第17行的C:\ WebServer\Apache24\Apache24\htdocs\html\www\SocialNetwork\my-account.php中的application/x-www-form-urlencoded
虽然这不会破坏我的应用程序,但这很烦人.我该如何解决?
我试图在标题部分添加"User-Agent:MyAgent/1.0\r \n"和"Connection:close"但它似乎没有修复它!
我在尝试使用file_get_contents和捕获cookie时收到无效的cookie字符串curl.直接从浏览器浏览时收到的cookie是有效/活动的.但是,从捕获的饼干file_get_contents和curl似乎是无效的.
我试图从file_get_contents这样捕获
$context = array(
'http' => array(
'method' => 'GET',
'header' => array('Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*\/*;q=0.8', 'User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/63.0.3239.84 Chrome/63.0.3239.84 Safari/537.36'),
)
);
$cxContext = stream_context_create($context);
file_get_contents($url, false, $cxContext);
$cookies = array();
foreach ($http_response_header as $hdr) {
if (preg_match('/^Set-Cookie:\s*([^;]+)/', $hdr, $matches)) {
$cookies = $matches[1];
}
}
return $cookies;
Run Code Online (Sandbox Code Playgroud)
我试着通过设置标题来解决这个问题,但是返回的cookie总是过期或者无效.
但是,通过浏览器,我获得的cookie始终有效.
任何人都遇到类似问题,不知道如何解决这个问题.
我正在尝试使用 PHP 获取文件的内容。然后将其添加到新文件中。我正在使用file_get_contents()但它显示错误:
PHP Warning: file_get_contents(./home-starter.php): failed to open stream: No such file or directory
Run Code Online (Sandbox Code Playgroud)
尽管路径是正确的。两个文件位于同一文件夹中。
Main Folder
errorfile.php
home-starter.php
Run Code Online (Sandbox Code Playgroud)
有什么建议么?
<?php
require_once('private/initialize.php');
$city = 'Lahore';
$keyword = 'Homemade Food';
$areas = ['DHA', 'Bahria Town', 'Cantt', 'Gulberg', 'Valencia Town', 'Sui Gas Housing Society', 'Izmir Town', 'Faisal Town', 'Garden Town', 'Johar Town', 'Punjab Housing Society', 'Canal Housing Societies', 'State Life Housing Society', 'Model Town', 'Liaqatabad', 'Rehmanpura', 'Samanabad', 'Muslim Town', 'Town Ship', 'Iqbal Town', 'Ferozepure Road', 'Multan Road', 'Baghbanpura', 'Mughalpura', …Run Code Online (Sandbox Code Playgroud)