首页 > 解决方案 > 如何调试为什么 file_get_contents() 中的 HTTP 提取不起作用

问题描述

我正在尝试以file_get_contents不同的方式使用。不知何故,它不以这种方式工作。请看代码

<?php
$attrb = "https://html5andcss3.org";
$htmlcontent = file_get_contents("'" .$attrb . "'");
echo $htmlcontent;
?>

我收到错误消息

在此处输入图像描述

但是当我以正常方式使用此代码时,它工作正常。请参阅下面的工作代码

<?php
$htmlcontent = file_get_contents('https://html5andcss3.org');
echo $htmlcontent;
?>

我的问题是,我将在变量中获取 URL,我需要从那里开始。所以不能直接放网址。

标签: php

解决方案


变量的值已经是一个字符串。你不需要用额外的引号括起来:

$htmlcontent = file_get_contents($attrb);

推荐阅读