【问题标题】:Undefined offset: 1 file_get_contents未定义的偏移量:1 file_get_contents
【发布时间】:2013-04-23 18:34:13
【问题描述】:

我最近更改了我的服务器代码,但在我的旧服务器上它运行良好。

<?php
ini_set('display_errors', 1);
ini_set('error_reporting', E_ALL | E_STRICT);

$myid = "110988448104041785223";
$plus = file_get_contents("http://plus.google.com/$myid/plusones");
$match = array(); 
preg_match('/<div aria-hidden="true" class="BT"><a href="(.*?)"/',$plus,$match);
$data['url'] = $match[1];
echo strtolower($data['url']);
?>

Reurn: Undefined offset: 1 in .... on line 9

我已经在 .htaccess 中添加了这个(我不知道这是否有必要):

php_value magic_quotes 0
php_flag magic_quotes Off
php_value magic_quotes_gpc 0
php_flag magic_quotes_gpc Off
php_flag allow_url_include On

PHP 版本 5.2.17 - 旧服务器工作正常;和 PHP 版本 5.3.23 - 新服务器。

谢谢

【问题讨论】:

  • $match[1] 不存在我猜。在尝试使用它们之前检查你的匹配项
  • 你能检查一下吗? codepad.viper-7.com/bNeBUV

标签: php undefined file-get-contents offset


【解决方案1】:

这意味着它没有找到匹配项,但无论如何您都在尝试访问结果数组。

你应该有这个:

if( preg_match('/<div aria-hidden="true" class="BT"><a href="(.*?)"/',$plus,$match)) {
    $data['url'] = $match[1];
    echo strtolower($data['url']);
}
else echo "ERROR: No match found!";

【讨论】:

  • 谢谢你,但通常他必须找到一个匹配...link
猜你喜欢
  • 2022-01-02
  • 2011-07-22
  • 1970-01-01
  • 2021-07-12
  • 1970-01-01
  • 2021-08-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多