2011-12-09 21 views
-1

こんにちは、私は次のエラーを取得していオフセットPHPのエラー通知:未定義は

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

ライン113が$であるpublish_content = $ matches2 [1];

これはこれはあなたの配列変数$matches1 doesntのは、キー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または1つの値しか持たないため、$matches2[1]は無効なオフセットです。

これは、preg_matchのdoestがあなたの$itemと一致する場合に発生します。

+0

これを解決する方法は?どの行が? –

+0

@MSona:このコードが何をしているのかわからないので、私たちはそれを伝えることはできません。しかし、先頭のif文とループは、 '$ matches2'が初期化されていない状態で実行が行113に達するため、何らかの点で明らかに間違っています。 – Boann

関連する問題