在下面的函數中,我應該如何初始化$匹配以避免在註釋行上拋出未定義的索引?未定義的偏移量:0 preg_match中的錯誤
function save_rseo_nofollow($content) {
$my_folder = get_option('rseo_nofollow_folder');
preg_match_all('~<a.*>~isU',$content["post_content"],$matches);
for ($i = 0; $i <= sizeof($matches[0]); $i++){
if (!preg_match('~nofollow~is',$matches[0][$i]) //ERROR UNDEFINED OFFSET HERE!
&& (preg_match('~' . $my_folder . '~', $matches[0][$i])
|| !preg_match('~'.get_bloginfo('url').'~',$matches[0][$i]))){
$result = trim($matches[0][$i],">");
$result .= ' rel="nofollow">';
$content["post_content"] = str_replace($matches[0][$i], $result, $content["post_content"]);
}
}
return $content;
}
@Scott B:由於`$ i`在**循環中定義**,所以包裝將不起作用;)。 – Shikiryu 2011-02-11 17:04:50
是的,我發現並刪除了我的評論。你打敗了我。 +1爲您提供幫助。現在我有另一個問題,我會問另一個問題相同的功能:) – 2011-02-11 17:27:09