假设在下面的代码中,#bob 和 #test 匹配,那么 preg_replace 表达式将是什么,以便 #bob 和 #to 是 url(即http://test.com/read.php?id=bob) ? 注意 id=bob 部分没有标签。
$text = "my name is #bob and I like #to #test things.";
preg_match_all("/(#\w+)/", $text, $matches);
foreach($matches['0'] as $match){
$substring = substr($match, 1);
$titlerows = mysql_num_rows(mysql_query("SELECT title FROM title WHERE title='$substring'"));
if($titlerows == 1) {
$text = preg_replace('/$match/', replace?? , $text);
}
}
echo $text;