2011-02-12 51 views
0

在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的?

回答

2

我認爲實際的問題可能是這一行:

$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的正確格式和返回正確的圖像文件名路徑,否則失敗,如果不匹配,沒有錯誤。

+0

我不太清楚我在做什麼,但這工作$ split_url = preg_match(「#$標記(/.+)$#」,$ img_url,$ split_url); – tokyowp 2011-02-12 14:40:13