-
-
/** - * 内容关键词的替换
- * edit: WWW.JBXUE.COM
- */
$ci=array("短网址"=>"http://jbxue.com","网址缩短"=>"http://jbxue.com");
//内容字段是content
- $content="短网址是个好工具";
- foreach($ci as $k=>$v){
- $str=''.$k.'';
- $content=ereg_replace($k,$str,$content);
- }
- echo $content;
-
复制代码
附,帝国cms中的关键字替换代码:
-
- //替换关键字
- function ReplaceKey($newstext){
- global $empire,$dbtbpre,$public_r;
- if(empty($newstext))
- {return $newstext;}
- $sql=$empire->query("select keyname,keyurl from {$dbtbpre}enewskey order by length(keyname) desc"); //按字段内容长度排序
- while($r=$empire->fetch($sql))
- {
- $newstext=empty($public_r[repkeynum])?str_replace($r[keyname],''.$r[keyname].'',$newstext):preg_replace('/'.$r[keyname].'/',''.$r[keyname].'',$newstext,$public_r[repkeynum]);
- }
- return $newstext;
- }
复制代码
|