2011-12-09 2 views
-1

안녕하세요 저는 다음과 같은 오류를 받고 있어요 오프셋PHP 오류 공지 사항 : 정의되지 않은이

Notice: Undefined offset: 1 in file.php on line 113 

라인 113 $입니다 publish_content = $ matches2 [1]

이것은이 배열 변수 $matches1 나던 1 키가 포함되어 있음을 의미 내 코드

if(!preg_match('/\<content\:encoded\>(?:\<\!\[CDATA\[)?(.*?)(?:\]\]\>)?\<\/content\:encoded\>/si',$item,$matches2)){ 
     for($i2=0;$i2<count($info_tag_pairs);$i2++){ 
      if(preg_match('/'.custom_preg_quote($info_tag_pairs[$i2][0]).'(.*?)'.custom_preg_quote($info_tag_pairs[$i2][1]).'/si',$item,$matches2)){ 
       break; 
      } 
     } 
    } 

    $publish_content=$matches2[1]; 
    $publish_content=strip_tags($publish_content); 
    $publish_content=preg_replace('/'.arrayToString($rkws,'|','custom_preg_quote').'/si','',$publish_content); 
    $publish_content=trim($publish_content); 
    //echo $item; 
    if(!preg_match_all('/\<category\>(?:\<\!\[CDATA\[)?(.*?)(?:\]\]\>)?\<\/category\>/si',$item,$matches2)){ 
     for($i2=0;$i2<count($category_tag_pairs);$i2++){ 
      if(preg_match_all('/'.custom_preg_quote($category_tag_pairs[$i2][0]).'(.*?)'.custom_preg_quote($category_tag_pairs[$i2][1]).'/si',$item,$matches2)){ 
       break; 
      } 
     } 
    } 
+1

** 줄이있는 곳 113 ** ** – ajreal

+0

변수 내용은 무엇입니까? – Alex

+1

dodgy regexps로 싸우는 대신 실제 XML 파서를 사용하도록 코드를 변경하는 것이 좋습니다. – Boann

답변

0

PHP에서 던져진 알림을 피하는 방법은 값으로 무엇인가를하기 전에 값이 설정되면 테스트입니다.

<?php 

if (isset($matches2[1])) { 
    // do what you need with $matches2[1] 
    // ... 
} 

// or 

if (! isset($matches2[1])) { 
    // here you are sure $matches2[1] doesn't exist 
    return; 
} 
0

입니다. $matches2[1]에 액세스 중이므로 $matches2은 비어 있거나 null이거나 값이 하나뿐이므로 $matches2[1]은 잘못된 오프셋입니다.

preg_match 사용자가 $item과 일치하는 경우 이러한 현상이 발생할 수 있습니다.

+0

어떻게 해결할 수 있습니까? 어떤 줄이?로 바꿉니 까? –

+0

@MSona : 우리는이 코드가 무엇을하고 있는지 알지 못하기 때문에 말할 수 없습니다. 그러나'$ matches2'가 초기화되지 않은 상태에서 실행이 113 행에 도달 할 수 있기 때문에 가장 상위의 if 문과 루프는 어떤면에서는 분명히 잘못되었습니다. – Boann

관련 문제