【问题标题】:PHP error when trying to access Factual API尝试访问 Factual API 时出现 PHP 错误
【发布时间】:2016-05-31 08:56:50
【问题描述】:

我正在为我的 PHP 框架使用 WAMP。我正在尝试测试此代码

<?php
require_once "C:\wamp\www\factual-php-driver-master\Factual.php";
$factual= new Factual("/*API Key*/","/*API Secret*/");

$query= new FactualQuery;
$query->limit(3);
$res= $factual->fetch("places", $query);
print_r($res->getData());
?>

我的 Factual.php 文件的 PATH 绝对正确,但文件返回以下错误

警告:require_once(C:\wamp\wwwactual-php-driver-master\Factual.php):无法打开流:在线 C:\wamp\www\foodmeets\restaurants.php 中的参数无效2

致命错误:require_once():在 C 中打开所需的 'C:\wamp\wwwactual-php-driver-master\Factual.php' (include_path='.;C:\php\pear') 失败:\wamp\www\foodmeets\restaurants.php 第 2 行

请注意,我已经使用命令对 PHP 安装环境进行了测试

php -f test.php yourFactualKey yourFactualSecret [logfile]

如 Github 上 PHP 的 Factual Driver(V3) 中所述(https://github.com/Factual/factual-php-driver)

【问题讨论】:

    标签: php factual


    【解决方案1】:

    您必须转义 \f(\f 元字符用于查找换页符。)

    require_once "C:\wamp\www\\factual-php-driver-master\Factual.php";
    

    【讨论】:

    • 是的,它现在正在工作,但你能解释一下为什么会这样吗?
    • 实际上是 C:\wamp\www\factual-php-driver-master\Factual.php,在这个 \factual-php-driver-master 中有 \f 这是用于查找表单提要的元字符特点。在 php 中,我们需要通过使用额外的反斜杠来转义所有这些事情,因此 \\factual-php-driver-master.
    【解决方案2】:

    您的反斜杠被 PHP 转换为特殊字符。 例如,...arrays\news.php 变成了

    ...数组

    新闻.php

    你应该像这样逃避它们:

    $path = "C:\NucServ\www\vv\static\arrays\news.php"; 或者使用单曲,像这样:

    $path = 'C:\NucServ\www\vv\static\arrays\news.php';

    另外,你的 if 搞砸了。你不应该再次打开文件。只需使用您已有的 $fp。

    来源failed to open stream: Invalid argument

    【讨论】:

      猜你喜欢
      • 2021-10-30
      • 2021-09-24
      • 1970-01-01
      • 1970-01-01
      • 2012-11-01
      • 2021-05-03
      • 1970-01-01
      • 2016-04-19
      • 2018-07-17
      相关资源
      最近更新 更多