php - 如何调试为什么 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,我需要从那里开始。所以不能直接放网址。
解决方案
变量的值已经是一个字符串。你不需要用额外的引号括起来:
$htmlcontent = file_get_contents($attrb);
推荐阅读
- php - 需要帮助在 PHP 中仅显示这些文本行
- sql - 使用 IN 运算符的查询在 SQL Server 中表现不佳
- c# - 通过外部设备发送短信
- r - 用 R 中的 NA 值计算数据集的每一行的线系数
- python - 在 Docker 中与远程服务器的连接不稳定
- python - 从 VGG16 模型到 Mobilenet 再到 android studio
- javascript - Redux 过滤数组
- python - 在 Django 中将多个模型(mysql)组合到模板中
- javascript - 如何突出显示 chartjs 中的特定数据点,我的数据来自 json 数组?
- react-native - 如何集成 squareup 支付方式以在 react-native 应用程序中获取 nonce?