2010-12-31 16 views
10

は誤りです:strpos() "空の区切り文字"エラーを解決するにはどうすればよいですか?ここ

の場合:PHP 5.2+

Warning: strpos() [function.strpos]: Empty delimiter in /helper.php on line 445

、ここでは、その行のコードは次のとおりです。

if($src = $img->getAttribute('src') AND strpos($src,$fgParams->get('base')) === false) { // prevents repeat processing 
      EgivaUtility::profiling('Processing Image SRC: '.$src); 
      // fix rel paths 
      $src = EgivaUtility::encode_url(EgivaUtility::makeAbsUrl($origLink,$src)); 
      if($image_details = @getimagesize($src) AND !in_array($image_details[0],array(1,2)) AND !in_array($image_details[1],array(1,2))) { 
       EgivaUtility::profiling('Image Details: '.print_r($image_details,true)); 
       $title = $img->getAttribute('title'); 
       $alt = $img->getAttribute('alt'); 
       if($fgParams->get('save_img')) { // consider restoring the JPath::clean() 
        // find image name and extension 
        $name = $title ? EgivaUtility::stringURLSafe($title) : EgivaUtility::stringURLSafe($alt); 
        preg_match('#[/?&]([^/?&]*)(\.jpg|\.jpeg|\.gif|\.png)#i',$src,$matches); 
        $ext = isset($matches[2]) ? strtolower($matches[2]) : ''; 
        if(!$name) $name = isset($matches[1]) ? EgivaUtility::stringURLSafe($matches[1]) : md5($src); 
        unset($matches); 
        //create image file  
        $filename = $fgParams->get('name_prefix').$name.$ext; 
        $filepath = $fgParams->get('savepath').'images'.DS.$filename; 
        if(!file_exists($filepath)) { 
         if($contents = EgivaUtility::getUrl($src,$fgParams->get('scrape_type'),'images',$filepath)) { 
          $saved = true; 
          //if(EgivaUtility::savefile($contents,$name,$update=false,$header=null,$fgParams->get('savepath').'images')) $saved = true; 
         } 
        } else { 
         $saved = true; 
        } 
        if($saved) $img->setAttribute('src', $fgParams->get('srcpath').'images/'.$filename); 
       } else { 
        $img->setAttribute('src',$src); 
       } 
       EgivaUtility::profiling('Final Image SRC: '.$img->getAttribute('src')); 
      // $class = $img->getAttribute('class'); 
      // $width = $img->getAttribute('width'); 
      // $height = $img->getAttribute('height'); 
       if(strlen($alt) >= JString::strlen($content['title']) OR !$alt) { 
        $img->setAttribute('alt',$content['title']); 
       } 
       if($fgParams->get('rmv_img_style')) { 
        $img->removeAttribute('class'); 
        $img->removeAttribute('style'); 
        $img->removeAttribute('align'); 
        $img->removeAttribute('border'); 
        $img->removeAttribute('width'); 
        $img->removeAttribute('height'); 
       } 
       if($fgParams->get('img_class')) { 
        $img->setAttribute('class',$fgParams->get('img_class')); 
       } 
       $new_img = $dom2->importNode($imgs->item($k),true); 
       $dom2->appendChild($new_img); 
       $images[$k] = $dom2->saveHTML(); 
       $dom2->removeChild($new_img); 

       // hack to avoid encoding problems 
       $text = preg_replace($regex,'fg_img'.$k,$text,$limit=1); 
       $replace[$k] = 'fg_img'.$k; 
       $k++; 
      } else { 
       EgivaUtility::profiling('Image Rejected'); 
       $text = preg_replace($regex,'',$text,1); 
      } 
     } 
    } 
+0

どの行が445行ですか? –

+0

申し訳ありません - 行445は、上記のコードの最初の行です。つまり、$ src = $ img-> getAttribute( 'src')とstrpos($ src、$ fgParams-> get( 'base') )=== false){ – Jamison

+0

helper.phpファイルをチェックして、行番号445を確認してください。行番号445に正確に何かお知らせください。 –

答えて

33

strposへの2番目のパラメータがある場合に、このエラーが発生します空の。例えば、私は簡単にコマンドラインでこのエラーをシミュレートすることができます:あなたのコードで

$ php 
<?php 
echo strpos("foo", ""); 
?> 
^D 
Warning: strpos(): Empty delimiter in - on line 2 

は、それが$fgParams->get('base')が空であることを意味しています。

コードにいくつかのチェックを追加して、strposに渡す値が有効で、エラーがなくなることを確認します。

1

if($src = $img->getAttribute('src') AND $fgParams->get('base')!="" AND strpos($src,$fgParams->get('base')) === false) { // prevents repeat processing 

if($src = $img->getAttribute('src') AND strpos($src,$fgParams->get('base')) === false) { // prevents repeat processing 

から445

変更ラインは何も返さないでその取得( '基本')のように思えます。これはあなたのスクリプトで可能ですか?おそらくそれはプログラムの別の領域における以前のエラーの兆候でしょう。

0

$ fgParams-> get( 'base')の値が、条件に記載されているjsonのように空白でないことを確認してください。

0

私は同じ問題が持っていた:

if (htmlentities($controleren[$aantaltekens]) == htmlentities($trans[$tellen])) 

ので、試してみてください:

if(($src = $img->getAttribute('src') AND strpos($src,$fgParams->get('base'))) === false) 

推測htmlentitiesはそのを必要とエラーが、私は2つの()区切り文字を追加したときに消え

if (htmlentities($controleren[$aantaltekens] == htmlentities($trans[$tellen]) 

を(区切り文字)内にあるパラメータ。

+1

ようこそStackOverflow!あなたの答えを少し書式化すれば、それは読みやすくなり、より高い人がそれに投票する可能性があります。テキストの下の_editt_ボタンを使用して編集できます。 –

関連する問題