标签: file-get-contents

检查 URL 是否返回 PDF

我需要检查 URL 是否使用 PHP 返回 PDF 文档。现在我正在使用 file_get_mimetype 函数。普通 URL ( https://www.google.com/ ) 返回类型为 application/octet-stream 而普通 pdf 链接 ( http://www.brainlens.org/content/newsletters/Spring%202013.pdf ) 返回应用程序/pdf。但现在我也遇到了像http://www.dadsgarage.com/~/media/Files/example.ashxhttp://www.wpdn.org/webfm_send/241这样的URL ,它也是 pdf 但返回 application/octet-溪流。还有其他 URL 也会打开一个另存为对话框,也必须检测到。

php url file-get-contents

0
推荐指数
1
解决办法
2761
查看次数

PHP 中的连接 URL

当我尝试将变量与 URL 连接时遇到问题

这有效:

$id = 123;
$url = file_get_contents("http://127.0.0.1:8080/api/table.json?output=html&udptype=trap&udpmsgid=".$id."&content=udpmessage");
Run Code Online (Sandbox Code Playgroud)

但这不起作用

$id = $_GET['id'];
$url = file_get_contents("http://127.0.0.1:8080/api/table.json?output=html&udptype=trap&udpmsgid=".$id."&content=udpmessage");
Run Code Online (Sandbox Code Playgroud)

我不知道我是否正确连接了变量。

php url concatenation file-get-contents

0
推荐指数
1
解决办法
1524
查看次数

有没有办法用 php file_get_contents 解决 403 错误?

我正在尝试使用 php file_get_contents 获取特定网页 - 当我直接查看页面时没有问题,但是当尝试使用 php 抓取它时,我得到“无法打开流:HTTP 请求失败!HTTP/1.1 403 禁止”。我试图从页面中提取一段数据。

$ft = file_get_contents('https://www.vesselfinder.com/vessels/CELEBRITY-MILLENNIUM-IMO-9189419-MMSI-249055000');

echo $ft;
Run Code Online (Sandbox Code Playgroud)

我已经在这里阅读了有关使用 stream_context_create 的各个页面,主要是用户代理部分

$context  = stream_context_create(
array(
    "http" => array(
        "header" => "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36"
    )
)
Run Code Online (Sandbox Code Playgroud)

);

但是没有任何效果,我现在收到 400 错误消息。不幸的是,我的服务器似乎没有配置为使用 cURL,因此 file_get_contents 似乎是我执行此操作的唯一方法。

php file-get-contents

0
推荐指数
1
解决办法
2443
查看次数

使用带有基本身份验证和 SSL 的 file_get_contents

我正在尝试GET使用 SSL 和使用以下file_get_contents功能的基本身份验证请求:

$username = "XXXXXXXXXX";
$password = "XXXXXXXXXX";

$url = "https://stream.watsonplatform.net/authorization/api/v1/token?url=https://stream.watsonplatform.net/speech-to-text/api";

$context = stream_context_create(array("http" => array("header" => "Authorization: Basic " . base64_encode("$username:$password"))));

$data = file_get_contents($url, false, $context);

echo $data;
Run Code Online (Sandbox Code Playgroud)

这是我收到的错误消息:

警告:file_get_contents( https://stream.watsonplatform.net/authorization/api/v1/token?url=https://stream.watsonplatform.net/speech-to-text/api ):无法打开流:HTTP 请求失败的!HTTP/1.0 500 服务器错误...

我已经确认openssl已启用:

在此处输入图片说明

我们不妨提前解决这个问题:

为什么不直接使用 cURL?

我可以。但我也想弄清楚为什么file_get_contents不起作用。我喜欢file_get_contents. 叫我疯了。

php file-get-contents

0
推荐指数
1
解决办法
4503
查看次数

PHP 通过换行符和分隔符分解 .txt 文件 |

我有一个包含这些数据的log.txt文件:

2022-08-25 13:16----------817650|xx:xx:xx:xx:xx:xx|user1|10
2022-08-25 13:16----------817856|xx:xx:xx:xx:xx:xx|user1|5
Run Code Online (Sandbox Code Playgroud)

我想比较最后两行的最后一个值(10 和 5),但我在识别这些行时遇到了困难。

 <?php

    $textCnt  = "./log.txt";
    $contents = file_get_contents($textCnt);
    $arrfields = explode( "|" , $contents);
            
    
    echo $arrfields[3];

    ?>
Run Code Online (Sandbox Code Playgroud)

我懂了:

10 2022-08-25 13:16----------817856
Run Code Online (Sandbox Code Playgroud)

代替

10
Run Code Online (Sandbox Code Playgroud)

php explode file-get-contents separator

0
推荐指数
1
解决办法
260
查看次数

php bug if if不起作用

<?php   
$myip=file_get_contents("http://www.whatismyip.com/automation/n09230945.asp");
if(!$myip=='1.1.1.1'){

    echo "Not matches";
}
?>
Run Code Online (Sandbox Code Playgroud)

if不起作用?:S

php if-statement operators file-get-contents

-1
推荐指数
1
解决办法
71
查看次数

使用PHP获取XML文件的内容

可能重复:
file_get_contents与https?
使用SimpleXML和PHP通过https获取XML内容的问题

我有网址:

哪个加载像这样的文件:

<calendars>
    <calendar accommodation_id="1234567">
        <day date="2012-08-09" vacancy="false" minimum_nights="7" arrival_day="true"/>
        <day date="2012-08-10" vacancy="false" minimum_nights="3" arrival_day="true"/>
        <day date="2012-08-11" vacancy="false" minimum_nights="3" arrival_day="true"/>
        ...
        <day date="2014-01-31" vacancy="true" minimum_nights="3" arrival_day="true"/>
    </calendar>
</calendars>
Run Code Online (Sandbox Code Playgroud)

出于某种原因,我的脚本不会让我获取此文件的内容.我正在使用与其他URL相同的脚本,但这总是会失败.

我的脚本是:

$accom2 = file_get_contents();

print_r($accom2);
Run Code Online (Sandbox Code Playgroud)

我需要为这种类型的URL做些什么吗?

php xml url curl file-get-contents

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

PHP file_get_contents()返回启用cookie?

我正在尝试file_get_contents()https://satoshidice.com/api/status上执行此操作并将其返回 - http://puu.sh/58lCb

print file_get_contents($this->base . 'status');
Run Code Online (Sandbox Code Playgroud)

$this->base 是satoshidice.com/api(带有http).

为什么它会返回上面张贴的图片中的内容..?

php get http file-get-contents

-1
推荐指数
1
解决办法
1133
查看次数

如何将PHP变量放在file_get_contents URL字符串中?

我想更改下面的URL中的1并传递从网站URL拉出的PHP变量.除了我在下面的URL file_get_contents中间使用变量工作时,我还有其他一切正常工作.

$listingstring = file_get_contents('http://example.com/1/lsitngs/');

$listingstring = file_get_contents('http://example.com/?variable/lsitngs/');
Run Code Online (Sandbox Code Playgroud)

php variables json file-get-contents

-2
推荐指数
1
解决办法
1144
查看次数

使用其他IP发送获取请求

我想使用file_get_contents(URL)向网站发送获取请求。但是问题是URL仅接受来自某些IP地址的请求。我想知道是否可以从Web服务器发送相同的请求,以便该请求在该服务器上看起来就像该请求来自允许的IP

php ip tunnel file-get-contents

-2
推荐指数
1
解决办法
853
查看次数

PHP获取文件内容

我试图在另一个网站上显示一个网站的内容.这就是我目前拥有的:

<?php 
  $file = file_get_contents ('http://linkto.com/the-page'); 
  echo $file; 
?>
Run Code Online (Sandbox Code Playgroud)

它从该页面获取所有内容.但是,我只需要从中获取一个表.我基本上只需要从所有的内容<table id=arc>,以</table>.

有没有简单的方法来编辑我的代码才能获得该表?

php file-get-contents

-3
推荐指数
1
解决办法
4003
查看次数