Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 注意:未定义的偏移量:0_Php - Fatal编程技术网

Php 注意:未定义的偏移量:0

Php 注意:未定义的偏移量:0,php,Php,我一直在开发一些应用程序,其中包括cURL操作,然后删除特定URL的内容 刮削后的计算也很少 我现在面临的问题与未定义的数组索引有关 以下是一些职能部门面临的类似问题: {注意:第263行的D:\xampp\htdocs\Alps-Phase2\Alps\include\alpsOP\scrap-process-request2.php中未定义的偏移量:0} 还有更多类似的功能: function getDomainName($objScrap) { try { $result = $

我一直在开发一些应用程序,其中包括cURL操作,然后删除特定URL的内容

刮削后的计算也很少

我现在面临的问题与未定义的数组索引有关

以下是一些职能部门面临的类似问题:

{注意:第263行的D:\xampp\htdocs\Alps-Phase2\Alps\include\alpsOP\scrap-process-request2.php中未定义的偏移量:0}

还有更多类似的功能:

function getDomainName($objScrap)
 {
try
{
    $result = $objScrap->getDomainName();

    return $result;  //Notice: Undefined offset: 0 
}
catch( Exception $e)
{
    echo "Error in getDomainName !";
    return FALSE;
}

  }

  function getDataForDomainName($objScrap)
  {
try
{
    $result = $objScrap->checkForKeywordInDomain();

    return $result[0];    // Notice: Undefined offset: 0 
}
catch( Exception $e)
{
    echo "Error in getDataForDomainName !";
    return FALSE;
}
 }

function getDensityForDomainName($objScrap){
try
{
    $result = $objScrap->getDomainDensity();
    return $result[0];        // Notice: Undefined offset: 0 
}
catch( Exception $e)
{
    echo "Error in getDensityForDomainName !";
    return FALSE;
}
  }
某些调用的函数定义:

   function getDomainDensity()
  {
    $result=$this->getDomainName();
    return $this->getKeywordDensity($result);
  }
   function getDomainName()
  {
    preg_match($this->_regExpDomain,$this->_url,$match);

    if($match != NULL)
    return $match[2];
    else
    return array(
    0=> 'Please check URL '.$this->$_url.' [Domain Name]',
    'error' => 'Please check URL '.$this->$_url.' [Domain Name]'
                            );
  }



   function getKeywordDensity(&$subject)
    {
    $splitKeywordCountTotal_len=0;
    $splitKeywordCount = array();
    $resultArray = array();

      for($count_i=0;$count_i<count($this->_keywords);$count_i++)
        {


        $splitKeyword = $this->splitKeyword($this->_keywords[$count_i]);

        $splitKeywordCount=0;
        $splitKeywordCount = $this->prepareResultArray($subject,NULL,$splitKeyword);

        $matchedKeywordCharacterCount=0;
        $f=0;

        foreach ($splitKeywordCount as $val=>$key)
        {
            $splitKeywordCount[$f][2]=strlen($key[0]);

            $splitKeywordCount[$f][3]=$key[1]*strlen($key[0]);
            $matchedKeywordCharacterCount=$matchedKeywordCharacterCount+$splitKeywordCount[$f][3];
            $f++;

        }

        $totalWordsInVisibleContent = $this->getNumberOfWordsInSubject($subject);
        $f=0;
        $totalWordsInVisibleContent_len=0;
        foreach ($totalWordsInVisibleContent as $val=>$key)
        {
            $totalWordsInVisibleContent_len=$totalWordsInVisibleContent_len+strlen($key);
        }

        $splitKeywordCountTotal = 0;
        for($count_j=0;$count_j < count($splitKeywordCount);$count_j++)
        {
            $splitKeywordCountTotal = $splitKeywordCountTotal + $splitKeywordCount[$count_j][1];
            $splitKeywordCountTotal_len = $splitKeywordCountTotal_len + $splitKeywordCount[$count_j][2];

        }

        $resultArray[$count_i]      =   array();
        $resultArray[$count_i][0]   =   $this->_keywords[$count_i];
        $resultArray[$count_i][1]   =   $matchedKeywordCharacterCount/ ($totalWordsInVisibleContent_len);
        $resultArray[$count_i][2]   =   $splitKeywordCountTotal;
        $resultArray[$count_i][3]   =   $matchedKeywordCharacterCount;
        $resultArray[$count_i][4]   =   $totalWordsInVisibleContent;
        $resultArray[$count_i][5]   =   $splitKeywordCountTotal_len;
        $resultArray[$count_i][6]   =   $totalWordsInVisibleContent_len;

    }

    return $resultArray;
}
函数getDomainDensity() { $result=$this->getDomainName(); 返回$this->getKeywordDensity($result); } 函数getDomainName() { preg_match($this->_regExpDomain,$this->_url,$match); 如果($match!=NULL) 返回$match[2]; 其他的 返回数组( 0=>“请检查URL”。$this->$\u URL.[Domain Name]”, '错误'=>'请检查URL'.$this->$\u URL.[域名]' ); } 函数getKeywordDensity(&$subject) { $splitKeywordCountTotal\u len=0; $splitKeywordCount=array(); $resultArray=array(); 对于($count\u i=0;$count\u i\u关键字);$count\u i++) { $splitKeyword=$this->splitKeyword($this->_keywords[$count_i]); $splitKeywordCount=0; $splitKeywordCount=$this->prepareResultArray($subject,NULL,$splitKeyword); $matchedKeywordCharacterCount=0; $f=0; foreach($splitKeywordCount作为$val=>$key) { $splitKeywordCount[$f][2]=strlen($key[0]); $splitKeywordCount[$f][3]=$key[1]*strlen($key[0]); $matchedKeywordCharacterCount=$matchedKeywordCharacterCount+$splitKeywordCount[$f][3]; $f++; } $totalWordsInVisibleContent=$this->getNumberOfWordsInSubject($subject); $f=0; $TotalWordsSinVisibleContent\u len=0; foreach($totalWordsInVisibleContent作为$val=>$key) { $totalWordsInVisibleContent\u len=$totalWordsInVisibleContent\u len+strlen($key); } $splitKeywordCountTotal=0; 对于($count_j=0;$count_j\u关键字[$count\u i]; $resultArray[$count_i][1]=$matchedKeywordCharacterCount/($totalWordsInVisibleContent\u len); $resultArray[$count_i][2]=$splitKeywordCountTotal; $resultArray[$count_i][3]=$matchedKeywordCharacterCount; $resultArray[$count_i][4]=$totalWordsInVisibleContent; $resultArray[$count_i][5]=$splitKeywordCountTotal_len; $resultArray[$count_i][6]=$totalWordsInVisibleContent\u len; } 返回$resultArray; } 此外,我计划为同一个应用程序运行50万个URL。如果这些通知继续出现,我的应用程序将面临性能不佳的问题

所以伙计们,需要帮助解决这个问题

**很抱歉起草了代码。。。刚进入论坛,Din不知道如何使用这些结构(

关闭Html错误

在顶部包括以下内容

error_reporting(E_ALL);
ini_set('display_errors', 'On');
ini_set('html_errors', 'Off'); 

就在今天,我遇到了这样一个问题!我使用了PHP7.3.5,我得到了同样的错误,在四处搜索时,我发现解决方案是:

而不是:

try
{
    $result = $objScrap->checkForKeywordInDomain();
    return $result[0];    // Notice: Undefined offset: 0 
}
try
{
    $result = $objScrap->checkForKeywordInDomain();

    if(isset($result[0])){
      return $result[0];
   }
}
更改为:

try
{
    $result = $objScrap->checkForKeywordInDomain();
    return $result[0];    // Notice: Undefined offset: 0 
}
try
{
    $result = $objScrap->checkForKeywordInDomain();

    if(isset($result[0])){
      return $result[0];
   }
}

希望这能帮助其他人{:)。

变量转储($result)在获得这些未定义偏移量的点上显示了什么?要么数组没有
0
键,要么它的键不是整数(例如散列)。你的数组只是没有索引0,即使你希望有。这是你的一个逻辑错误。@MarcB嘿,var_dump($result)给出了我们在函数中传递的任何网站URL的内容。这基本上是cURL对整个网站的响应。@deceze那么,你能告诉我如何将索引[0]添加到数组中吗?