Tag: 文件获取内容

替代file_get_contents?

$xml_file = file_get_contents(SITE_PATH . 'cms/data.php'); 问题是服务器禁用了URL文件访问。 我无法启用它,它是一个托pipe的东西。 所以问题是这样的。 data.php文件生成xml代码。 我怎样才能执行此操作并获取XML数据,而无需执行上述方法? 可能吗?

当url不存在时,file_get_contents

我正在使用file_get_contents()来访问一个URL。 file_get_contents('http://somenotrealurl.com/notrealpage'); 如果URL不是真实的,则返回此错误消息。 我怎么才能得到它的错误,以便我知道该网页不存在,并采取相应的行动,而不显示此错误消息? file_get_contents('http://somenotrealurl.com/notrealpage') [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in myphppage.php on line 3 例如在zend你可以说: if ($request->isSuccessful()) $client = New Zend_Http_Client(); $client->setUri('http://someurl.com/somepage'); $request = $client->request(); if ($request->isSuccessful()) { //do stuff with the result }

PHP cURL vs file_get_contents

访问REST API时,这两段代码有什么不同? $result = file_get_contents('http://api.bitly.com/v3/shorten?login=user&apiKey=key&longUrl=url'); 和 $ch = curl_init('http://api.bitly.com/v3/shorten?login=user&apiKey=key&longUrl=url'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); 他们两人产生同样的结果,由此判断 print_r(json_decode($result))

使用file_get_contents显示图像

我怎么能显示在php中使用file_get_contents检索到的图像? 我需要修改标题,只是回声或什么? 谢谢!

PHP并行curl请求

我正在做一个简单的应用程序,从15个不同的url读取json数据。 我有一个特殊的需要,我需要做这个serverly。 我正在使用file_get_contents($url) 。 因为我正在使用file_get_contents($ url)。 我写了一个简单的脚本,是这样的: $websites = array( $url1, $url2, $url3, … $url15 ); foreach ($websites as $website) { $data[] = file_get_contents($website); } 而且它被certificate是非常慢的,因为它等待第一个请求,然后做下一个请求。

如何使用CURL而不是file_get_contents?

我使用file_get_contents函数来获取和显示特定页面上的外部链接。 在我的本地文件中一切正常,但我的服务器不支持file_get_contents函数,所以我试着用下面的代码使用cURL: function file_get_contents_curl($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); $data = curl_exec($ch); curl_close($ch); return $data; } echo file_get_contents_curl('http://google.com'); 但它返回一个空白页面。 哪里不对?

为什么我在使用file_get_contents()时得到500错误,但在浏览器中工作?

$html = file_get_contents("https://www.[URL].com"); echo $html; 在错误日志中产生这个: PHP警告:file_get_contents(https:// www。[URL] .com)[function.file-get-contents]:未能打开stream:HTTP请求失败! 第13行“/Applications/MAMP/htdocs/test.php中的HTTP / 1.1 500内部服务器错误”; 但是,该网站在浏览器中正常工作。 我也尝试使用cURL。 我没有在日志文件中得到任何错误,但$html现在回声: “/”应用程序中的服务器错误。 你调用的对象是空的。 …一些更多的debugging信息 任何想法如何解决这个问题?

file_get_contents()是否有超时设置?

我正在循环中使用file_get_contents()方法调用一系列链接。 每个环节可能需要15分钟以上的时间来处理。 现在,我担心PHP的file_get_contents()是否有超时期限? 如果是的话,它会超时打电话,并移动到下一个链接。 我不想在没有事先完成的情况下打电话给下一个环节。 所以,请告诉我file_get_contents()是否有超时期限。 包含file_get_contents()的文件被设置为set_time_limit()为零(无限)。

如何在PHP中获取文件的内容types?

我正在使用PHP发送附件的电子邮件。 附件可以是几种不同文件types(pdf,txt,doc,swf等)中的任何一种。 首先,脚本使用“file_get_contents”获取文件。 之后,脚本在标题中回响: Content-Type: <?php echo $the_content_type; ?>; name="<?php echo $the_file_name; ?>" 如何为$ the_content_type设置正确的值?

file_get_contents()分解UTF-8字符

我从外部服务器加载HTML。 HTML标记具有UTF-8编码,包含字符如ľ,,,č,,,etc.等等。当我用如下的file_get_contents()加载HTML时: $html = file_get_contents('http://example.com/foreign.html'); 它混淆了UTF-8字符,并加载了Å,¾,¤和类似的废话,而不是正确的UTF-8字符。 我该如何解决这个问题? 更新: 我试着把HTML保存到一个文件并用UTF-8编码输出。 两者都不起作用,所以它意味着file_get_contents()已经返回了错误的HTML。 UPDATE2: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="sk" lang="sk"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <meta http-equiv="Content-Language" content="sk" /> <title>Test</title> </head> <body> <?php $html = file_get_contents('http://example.com'); echo htmlentities($html); ?> </body> </html>