- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我的全部代码:
<html>
<body>
<form>
Playlist to Scrape: <input type="text" name="url" placeholder="Playlist URL">
<input type="submit">
</form>
<?php
if(isset($_GET['url'])){
$source = file_get_contents($_GET['url']);
$regex = '/<a href="(.*?)" class="gothere pl-button" title="/';
preg_match_all($regex,$source,$output);
echo "<textarea cols=100 rows=50>";
$fullUrl = array();
foreach($output[1] as $url){
array_push($fullUrl,"http://soundcloud.com".$url);
}
$final = implode(";",$fullUrl);
echo $final;
echo "</textarea>";
}else{
echo "borks";
}
?>
</body>
</html>
昨天,一切顺利。代码应该执行的操作是:获取 Soundcloud URL,提取各个歌曲,然后像 Song1;song2;song3 这样打印它们
再说一遍,昨天效果很好,我想从那以后我就没有改变任何东西......
我尝试注释掉其他代码,只保留 $source = file_get_contents($_GET['url']);并回显 $source,但它返回空白,这让我认为这是 file_get_contents 的问题。
如果您知道为什么会发生这种情况,我将不胜感激。谢谢!
最佳答案
可能发生的情况是 file_get_contents
尝试访问的服务器上安装了新的 SSL 证书。在我们的例子中,目标服务器在其域上安装了来自另一个供应商和另一个通配符域的新 SSL 证书。
稍微改变一下我们的配置就可以解决这个问题。
$opts = array(
'http' => array(
'method' => "GET",
'header' => "Content-Type: application/json\r\n".
"Accept: application/json\r\n",
'ignore_errors' => true
),
// VVVVV The extra config that fixed it
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
)
// ^^^^^
);
$context = stream_context_create($opts);
$result = file_get_contents(THE_URL_WITH_A_CHANGED_CERTIFICATE, false, $context);
感谢this answer,我找到了这个解决方案。它甚至被否决了。
这无疑解释了 file_get_contents
突然停止工作的事实。
关于php - file_get_contents() 突然不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25983401/
我正在使用 file_get_contents() 加载一个文本文件以放入文本区域,出于某种原因,每次加载它时,原始文本前后都会插入空格。我知道在保存过程中没有插入空格,因为我从我的 FTP 客户端检
我正在尝试使用 fsockopen 上传超过 2gb 的大文件。但是 file_get_content 出现以下错误,我无法将大文件存储在内存中。我需要分块发送数据,但不知道如何执行此操作。请问有人可
我一直收到这个错误 Warning: file_get_contents failed to open stream: HTTP request failed! HTTP/1.1 401 Unauth
我正在尝试从 php 发送电子邮件我有一个包含所有值的 php 文件和其他 php 模板文件。 (两个文件在同一台服务器上) 例如,我正在使用 file_get_contents 获取 php 模板文
我正处于构建 PHP 应用程序的早期阶段,其中一部分涉及使用 file_get_contents()从远程服务器获取大文件并将它们传输给用户。例如,要获取的目标文件是 200 mB。 如果下载到服务器
我正在为我的博客的示例代码文件夹制作一个基本的 PHP 源代码查看器。 我这里的内容是否足以让它永远不允许查看此脚本所在目录之外的文件或此脚本目录的子目录?我猜还有比 startsWith 更好的解
我正在尝试使用 file_get_contents() 从页面获取 html。 以下效果很好:file_get_contents('http://www.mypage.com?Title=Title'
file_get_contents 是否维护换行符?我认为它做到了,但我已经尝试过: if($conn){ $tsql = file_get_contents('scripts/CreateT
我有一个具有以下架构的网站: End user ---> Server A (PHP) ---> Server B (ASP.NET & Database)
在 if 子句中用作测试条件时,如何防止 file_get_contents 创建空文件? 无论如何都会创建一个空文件,这会导致在不同方法中对 getimagesize() 的后续调用失败。 问题是,
我目前正在本地机器上测试我的代码,我希望它能够读取和写入我拥有的文本文件,所以我有以下代码: Warning: file_get_contents(~/Desktop/insta_user.txt):
在某人的服务器中,出于安全原因,file_get_contents 被禁用。我需要检索 xml 数据。那么,最好的做法是: 验证服务器是否支持file_get_contents? file_get_c
This question already has answers here: Warning: file_get_contents(): https:// wrapper is disabled i
在载入x秒钟后,是否有任何方法可以获取网页响应? 例如,我想创建一个获取youtube视频评论数量的api,但是正如您所知,当您打开youtube视频链接时,它会像加载评论一样2秒钟,因此,如果您知道
我正在尝试像这样从youtube读取视频信息: $vid='WwVZBfMlNPA'; $vurl='http://youtube.com/get_video_info?video_id='.$vid
更新 我解决了问题并发布了答案。但是,我的解决方案并不是 100% 理想。我宁愿只使用 clearstatcache(true, $target) 或 clearstatcache(true, $li
目前,我正在使用 file_get_contents() 将 GET 数据提交到网站数组,但在执行页面时出现此错误: fatal error :超出最大执行时间 30 秒 我真正希望脚本做的就是开始加
问题是当我使用file_get_contents从该网站获取源代码(HTML)时,我收到的结果不是纯html代码。 我使用的代码: $source = file_get_contents("http:
这是我的全部代码: Playlist to Scrape: "; $fullUrl = array(); foreach($output[1] as $ur
我是 PHP 新手,所以请多多关照:) 有时 file_get_contents 会完成其工作,有时则不会。我在网页上构建了一个简单的 URL 检查(如果存在)。但问题是,即使 URL 确实存在(手动
我是一名优秀的程序员,十分优秀!