如何修复wordpress主题的functions.php中的错误“Warning:split()[function.split]:REG_EMPTY”?
问题描述:
在WordPress使用tanzaku和得到这个错误如何修复wordpress主题的functions.php中的错误“Warning:split()[function.split]:REG_EMPTY”?
警告:分流()[function.split]:在/public/wp-content/themes/tanzaku/functions.php线REG_EMPTY 232
线232的functions.php:
else {
// ... or get original 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);
}
}
如何解决这个错误 “警告:拆分()[function.split]:REG_EMPTY” 从WordPress主题的functions.php的?
答
我认为实际的问题可能是这一行:
$mark = substr(strrchr($upload_path, "/"), 1);
它搜索尾随路径组件一些URL路径,但它会失败.../dir/upload/
与traling斜线。在这种情况下,一个方便的选择应该是:
$mark = basename($upload_path);
这是不可能永远是空的,从而避开失败的expode或分割之后。 (字符串分割是一个次优的方法了。)
一个完整的解决方法可能是也像更换$split_url = split($mark, $img_url);
:
preg_match("#$mark(/.+)$#", $img_url, $split_url);
这将确保$ img_url的正确格式和返回正确的图像文件名路径,否则失败,如果不匹配,没有错误。
我不太清楚我在做什么,但这工作$ split_url = preg_match(“#$标记(/.+)$#”,$ img_url,$ split_url); – tokyowp 2011-02-12 14:40:13