开发者

How to fix error "Warning: split() [function.split]: REG_EMPTY " from functions.php of wordpress theme?

开发者 https://www.devze.com 2023-02-09 22:36 出处:网络
Using tanzaku in wordpress and get this error Warning: split() [function.split]: REG_EMPTY in /public/wp-content/themes/tanzaku/functions.php on line 232

Using tanzaku in wordpress and get this error

Warning: split() [function.split]: REG_EMPTY in /public/wp-content/themes/tanzaku/functions.php on line 232

Line 232 in functions.php:

else {
    // ... or get ori开发者_Python百科ginal size info.
    $upload_path = trim( get_option('upload_path') );
    $mark = substr(strrchr($upload_path, "/"), 1); // default mark is 'uploads'
    $split_url = split($mark, $img_url);
    if ($split_url[1] != null) {
        $img_path = $upload_path . $split_url[1];
        list($w, $h) = @getimagesize($img_path);
    }
}

How do I fix this error "Warning: split() [function.split]: REG_EMPTY " from functions.php of wordpress theme?


I think the actual problem might be this line:

$mark = substr(strrchr($upload_path, "/"), 1); 

It searches some url path for the trailing path component, but it would fail for .../dir/upload/ with a traling slash. A convenient alternative in this case would be:

$mark = basename($upload_path);

This is unlikely to ever be empty, thus eschewing the failing expode or split afterwards. (The string splitting is a suboptimal approach too.)


A complete workaround might be to also replace the $split_url = split($mark, $img_url); with something like:

preg_match("#$mark(/.+)$#", $img_url, $split_url);

This will ensure the correct format of the $img_url and return the correct image filename path, or otherwise fail without error if it doesn't match.

0

精彩评论

暂无评论...
验证码 换一张
取 消