未初始化的字符串偏移量:0 代码点火器索引.php


Uninitialized string offset: 0 codeigniter index.php

A PHP Error was encountered
Severity: Notice
Message: Uninitialized string offset: 0
Filename: index.php
Line Number: 154

这是代码

if ( $stCurlHandle !== NULL )
{
    curl_setopt($stCurlHandle, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($stCurlHandle, CURLOPT_TIMEOUT, 12);
    $sResult = @curl_exec($stCurlHandle); 
    if ($sResult[0]=="O") //line number 154
     {$sResult[0]=" ";
     // echo $sResult; // Statistic code end
      }
    curl_close($stCurlHandle); 
}
curl_exec

返回数组,只返回字符串中的原始数据...如果您需要字符串的第一个字符,您可以使用

$sResult{0}

它很可能从失败的请求中返回false。在测试实际结果之前,应将其作为测试用例之一。

$sResult没有

偏移量为零。 尝试做

print_r($sResult);

在第 154 行之前,您将找出错误原因和解决方案。

如果

$sResult有可能返回 false,则它是一个布尔值,而不是字符串或数组。尝试将条件更改为:

if ($sResult !== FALSE && $sResult[0]=="O"({$sResult[0]=" ";}