strlen($b['name']) ) ? -1 : 1;}//改变标签关键字function tag_link($content){ $match_num_from = 1; //一篇文章中同一个关键字少于多少不秒文本(这个直接填1就好了) $match_num_to = 4; //一篇文章中同一个关键字最多出现多少次描文本(建议不超过2次) $posttags = array(array('name'=>'你好','url'=>'www.aa.com'),array('name'=>'你好啊','url'=>'www.aa.com')); if ($posttags) { usort($posttags, "tag_sort"); foreach($posttags as $tag) { $link = $tag['url']; $keyword = $tag['name']; //连接代码 $cleankeyword = stripslashes($keyword); $ex_word = preg_quote($cleankeyword,'\''); $url = " ".addcslashes($cleankeyword, '$').""; $limit = rand($match_num_from,$match_num_to); //不连接的 代码 $content = preg_replace( '|( ]+>)(.*)('.$keyword.')(.*)( ]*>)|U', '$1$2%&&&&&%$4$5', $content); $content = preg_replace( '|( )|U', '$1$2%&&&&&%$4$5', $content); $cleankeyword = preg_quote($cleankeyword,'\''); $regEx = '\'(?!((<.*?)|(<>]*?)>)|([^>]*?))\'s'; $content = preg_replace($regEx,$url,$content,$limit); $content = str_replace( '%&&&&&%', stripslashes($ex_word), $content); } } return $content;}?>