在下面的preg_match中,我将与两个静态字符串$url和$my_folder进行比较。。。
$url = get_bloginfo( url )
//$url = http://site.com
$my_folder = get_option( my_folder );
//$my_folder = http://site.com/somefolder;
$my_folder字符串后面有斜杠时,我得到了匹配项
http://somefolder/go/
但这并不能创造一个匹配。。。
http://somefolder/go
然而,另一个问题是,这也符合。。。
http://somefolder/gone
代码是。。。
$my_folder = get_option( rseo_nofollow_folder );
if($my_folder !== ) $my_folder = trim($my_folder, / );
$url = trim(get_bloginfo( url ), / );
preg_match_all( ~<a.*>~isU ,$content["post_content"],$matches);
for ( $i = 0; $i <= sizeof($matches[0]); $i++){
if($my_folder !== )
{
//HERES WHERE IM HAVING PROBLEMS
if ( !preg_match( ~nofollow~is ,$matches[0][$i])
&& (preg_match( ~ . $my_folder . /?$~ , $matches[0][$i])
|| !preg_match( ~ . $url . /?$~ ,$matches[0][$i])))
{
$result = trim($matches[0][$i],">");
$result .= rel="nofollow"> ;
$content["post_content"] = str_replace($matches[0][$i], $result, $content["post_content"]);
}
}
else
{
//THIS WORKS FINE, NO PROBLEMS HERE
if ( !preg_match( ~nofollow~is ,$matches[0][$i]) && (!preg_match( ~ .$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;