我该如何解析strpos()“空分隔符"?错误? [英] How do I resolve a strpos() "empty delimiter" error?

查看:87
本文介绍了我该如何解析strpos()“空分隔符"?错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是错误:

对于:PHP 5.2 +

For: PHP 5.2+

警告:strpos()[function.strpos]:/helper.php中第445行的空定界符

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);
            }
        }
    }

推荐答案

strpos 的第二个参数为空时,会发生此错误.例如,我可以在命令行上轻松模拟此错误:

This error occurs when the second parameter to strpos is empty. For instance, I can easily simulate this error at the command line:

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

在您的代码中,这意味着$fgParams->get('base')为空.

In your code, it means that $fgParams->get('base') is empty.

在代码中添加一些检查,以确保传递给 strpos 的值有效,并且错误将消失.

Add some checks to your code to ensure that the values you pass to strpos are valid, and the error will go away.

这篇关于我该如何解析strpos()“空分隔符"?错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆