标签: file-get-contents

Perl相当于PHP的get_file_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)

php perl get file-get-contents lwp

6
推荐指数
1
解决办法
3828
查看次数

Go lang中的PHP file_get_contents

我是Golang的新手.其实我是PHP开发人员.

我需要file_get_contentsGolang中的功能.

您可以根据我的要求为此提供代码或建议Golang库.

注意:请记住file-get-contents,不仅仅是"读取文件".

php file-get-contents go

6
推荐指数
1
解决办法
1946
查看次数

php 中超过 4095 个字符的长 URL

$url = "http://example.com/............."
Run Code Online (Sandbox Code Playgroud)

$url 大约有 4095 个以上的字符。我需要在 php 中访问这个 URL,但是如果我使用filefile_get_contents,它会返回一个错误

如何在 php 中打开或访问此 URL?

php url file-get-contents

5
推荐指数
1
解决办法
3419
查看次数

CURL或file_get_contents更新供稿列表?

我正在运行一个提要阅读器网站,那里会有很多RSS.我将尽可能经常同步这些提要,所以我找到了这两种方法.

1方法:使用CURL

$weblog_name = 'MyBlog';
$weblog_url = 'http://feeds.feedburner.com/myblog';
$ping_url = 'http://ping.feedburner.com';

$request = <<<EOT
<?xml version="1.0" encoding="iso-8859-1"?>
<methodCall>
<methodName>weblogUpdates.ping</methodName>
<params>
 <param>
  <value>
   <string>$weblog_name</string>
  </value>
 </param>
 <param>
  <value>
   <string>$weblog_url</string>
  </value>
 </param>
</params>
</methodCall>
EOT;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $ping_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_POST, true );
curl_setopt($ch, CURLOPT_POSTFIELDS, trim($request)); 
$result = curl_exec($ch);
curl_close($ch); 
Run Code Online (Sandbox Code Playgroud)

第二种方法:file_get_contents

file_get_contents("http://feedburner.google.com/fb/a/pingSubmit?bloglink=http://feeds.feedburner.com/myblog");
Run Code Online (Sandbox Code Playgroud)

我的问题是哪个是更好,更快的解决方案,一次ping至少50个Feed?

php rss curl file-get-contents

5
推荐指数
1
解决办法
1929
查看次数

cron job不会打开file_get_contents

我正在运行一个使用file_get_contents的php脚本,以便将列表中的内容邮寄到该远程文件中.如果我手动运行脚本一切正常,但当我离开它并等待cron运行时它不会得到那个远程内容.....这可能吗?我在这里复制一些代码,我认为问题是:

$flyer = file_get_contents('flyer.html');

$desti = $firstname." ".$lastname;

$mail = new phpmailer();

$mail->IsSMTP();
$mail->CharSet = 'UTF-8';
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "orion.xxxx.com"; // line to be changed
$mail->Port = 465; // line to be changed
$mail->Username = 'bob@xxxx.com'; // line to be changed
$mail->Password = 'xxxx90'; // line to be changed
$mail->FromName = 'Bob'; // line to be changed
$mail->From = 'bob@xxxx.com';// line to be changed

$mail->AddAddress($email, $desti);

$mail->Subject = 'The Gift Store';    // to be changed …
Run Code Online (Sandbox Code Playgroud)

php cron file-get-contents

5
推荐指数
1
解决办法
3637
查看次数

file_get_contents在读取文件时显示意外输出

我想输出内联jpg图像作为base64编码的字符串,但是当我这样做时:

$contents = file_get_contents($filename);
print "<img src=\"data:image/jpg;base64,".$contents."\"/>";
Run Code Online (Sandbox Code Playgroud)

$filename带有base64图像的本地文本文件在哪里.输出如下:

<img src="data:image/jpg;base64,/9j/4A..... (the rest of the file)...." />
Run Code Online (Sandbox Code Playgroud)

而且好像没有渲染图像,但是它来自哪里?它不在文本文件中.如果删除,图像将正确显示.

php base64 image file-get-contents

5
推荐指数
1
解决办法
1397
查看次数

CURL 仅在已修改的情况下获取文件

我如何了解文件是否被修改过以使用 CURL 打开流(然后我可以使用 file-get-contents 打开它)

谢谢

php curl file-get-contents

5
推荐指数
1
解决办法
3421
查看次数

HTTP请求失败!HTTP/1.1 503服务暂时不可用

我正在使用函数file_get_contents从网页获取内容.一些网站运作良好,但大多数网站给我这个错误

failed to open stream: HTTP request failed! HTTP/1.1 503 Service Temporarily Unavailable
Run Code Online (Sandbox Code Playgroud)

这是我的简单代码

echo file_get_contents("url");
Run Code Online (Sandbox Code Playgroud)

当我在浏览器中运行此URL时它工作正常.可能是什么问题?

php file-get-contents

5
推荐指数
1
解决办法
2万
查看次数

file_get_contents 返回 PHP 代码

当我file_get_contents()在本地文件上使用函数时,结果包含 php 代码,但我只需要 HTML。

正在读取的文件内容:

<?php echo '<p>Hello</p>';?>
Run Code Online (Sandbox Code Playgroud)

从位于同一文件夹中的不同文件调用 file_get_contents 的结果:

<?php echo file_get_contents('test.php'); //returns the following: string(31) "Hello'; ?>"
Run Code Online (Sandbox Code Playgroud)

如果我从外部服务器读取文件,它会返回 HTML - 正如我所期望的。所以问题是:如何从本地文件中获取 HTML 输出?谢谢你们。

php file-get-contents

5
推荐指数
1
解决办法
3732
查看次数

PHP HTTP 426 - file_get_contents 与 curl

我有一个简单的 PHP 脚本,它向外部 API 发送带有一些参数的 GET 请求,并接收一些 json 数据作为响应。

我用过file_get_contents这个,它在过去几个月里有效。

例子:

$url = 'https://example.com?param1=xxx&param2=yyy';
$data = file_get_contents($url);
Run Code Online (Sandbox Code Playgroud)

突然它停止工作,出现以下错误:

failed to open Stream: HTTP request failed!
HTTP1/1 426 Upgrade Required
Run Code Online (Sandbox Code Playgroud)

我用它替换了它cURL并且它起作用了:

function curlGet($url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    curl_close($ch);
    return $response;
}
Run Code Online (Sandbox Code Playgroud)

我的问题是:

  • 什么会导致这种行为?
  • 2种方法到底有什么区别?
  • 我应该总是使用 curl 吗?
  • 使用时有没有办法防止这个问题file_get_contents

我认为我服务器上的任何内容都没有改变。我也在本地测试了它,它有相同的问题/解决方案,所以我猜测外部服务器/API 发生了一些变化。

我正在使用 PHP7。

php curl http file-get-contents php-curl

5
推荐指数
1
解决办法
308
查看次数

标签 统计

file-get-contents ×10

php ×10

curl ×3

base64 ×1

cron ×1

get ×1

go ×1

http ×1

image ×1

lwp ×1

perl ×1

php-curl ×1

rss ×1

url ×1