php实现SEO伪原创同义词替换函数
作者:寒川 发布于:2010-5-31 15:17 Monday 分类:网页编程
近日和一朋友讨论PHP关于同义词替换的SEO伪原创问题,写了如下函数,并为emlog做成插件。
function strtr_words($str)
{
$words=array();
$content = file_get_contents('words.txt');//词库
$content = str_replace( "\r", "",$content); //去掉换行符(以便兼容Linux主机)
$content = preg_split('/\n/', $content, -1, PREG_SPLIT_NO_EMPTY);//\n分割字符
foreach($content as $k=>$v)
{
if($k!=0)
{
$str_data = explode('→',$v);//关键词分割符
$words+=array("$str_data[0]"=>"$str_data[1]");
}
}
return strtr($str,$words);//返回结果
}
词库words.txt格式如下:
恳求→哀求
悲悼→哀伤
悲痛→哀思
悲伤→哀痛
顺序→挨次
受饿→挨饿
靠拢→挨近
注意,每一行一组同义词,中间用“→”分割。
评论:
庄原
2010-08-23 08:11
2010-08-23 08:11
不起作用啊
words.txt
内容
你→啊
function strtr_words($str)
{
$words=array();
$content = file_get_contents('words.txt');//词库
$content = str_replace( "\r", "",$content); //去掉换行符(以便兼容Linux主机)
$content = preg_split('/\n/', $content, -1, PREG_SPLIT_NO_EMPTY);//\n分割字符
foreach($content as $k=>$v)
{
if($k!=0)
{
$str_data = explode('→',$v);//关键词分割符
$words+=array("$str_data[0]"=>"$str_data[1]");
}
}
return strtr($str,$words);//返回结果
}
$StarGet = "你";
$StarGet = strtr_words($StarGet);
echo $StarGet;
words.txt
内容
你→啊
function strtr_words($str)
{
$words=array();
$content = file_get_contents('words.txt');//词库
$content = str_replace( "\r", "",$content); //去掉换行符(以便兼容Linux主机)
$content = preg_split('/\n/', $content, -1, PREG_SPLIT_NO_EMPTY);//\n分割字符
foreach($content as $k=>$v)
{
if($k!=0)
{
$str_data = explode('→',$v);//关键词分割符
$words+=array("$str_data[0]"=>"$str_data[1]");
}
}
return strtr($str,$words);//返回结果
}
$StarGet = "你";
$StarGet = strtr_words($StarGet);
echo $StarGet;
日志分类
最近日志
随机日志
最新评论
- CCC certification
对这块还真是不... - 那风筝
happy new year ! - Roy
你好, 交换个链... - 太阳城娱乐网
说实话,对钛白... - 卡特&&艾弗森
不错啊!!,过段... - 奇遇
沙发 - 寒川
@Mr.邱℡:现在可... - Mr.邱℡
曾经加过,失效... - 寒川
@欧盛网络:链接... - 欧盛网络
换个链接好不?...
日志档案
- 2011年11月(2)
- 2011年9月(1)
- 2011年8月(2)
- 2011年7月(2)
- 2011年5月(1)
- 2011年3月(3)
- 2011年2月(2)
- 2010年12月(1)
- 2010年11月(2)
- 2010年10月(3)
- 2010年9月(9)
- 2010年8月(8)
- 2010年7月(13)
- 2010年6月(18)
- 2010年5月(24)
- 2010年4月(10)
- 2010年3月(14)
- 2010年2月(6)
- 2010年1月(7)
- 2009年11月(2)
- 2009年10月(3)
- 2009年9月(3)
- 2009年8月(8)
- 2009年7月(15)
- 2009年6月(14)
- 2009年4月(2)
- 2008年12月(1)
- 2008年6月(1)
- 2008年5月(10)
- 2008年4月(9)
- 2008年3月(5)
- 2008年2月(2)
- 2008年1月(5)
- 2007年12月(4)
- 2006年9月(6)
- 2006年7月(1)



2010-08-23 08:12