search
Homephp教程php手册php自动给文章加关键词链接的函数代码

php自动给文章加关键词链接的函数代码

Jun 13, 2016 am 11:56 AM
arrayhttplinkphpcodeKey wordsfunctionaddcopyarticleBaiduofautomaticLink

复制代码 代码如下:


$link = array(
'百度,http://www.baidu.com/',
'服务器软件,http://s.jb51.net/',
'脚本之家,http://www.jb51.net/',
);
$str = '在百度中搜索服务器软件就可以到脚本之家提供的软件

夏季不再穿长筒袜近年成为一种时尚,甚至到了秋天也不例外。

专家提出,其实这种时尚不利于美腿。据悉,久坐久站缺少运动等原因易导致静脉曲张,尤其是长期站立工作的人,容易引起下肢静脉本身扩张、延长或静脉瓣膜损坏以至发病。具体表现为腿部肿胀,下肢静脉犹如蚯蚓状弯曲或结节成团,皮肤发紫,特别是踝和小腿内侧更为严重。

专家指出,长期站立工作的人或多或少都有一些下肢静脉曲张的表现,只是轻重程度不一样。下肢静脉曲张是一种治疗起来比较麻烦的疾病,严重的需要手术,所以最好的方法还是防患于未然,在症状尚不明显的时候,就采取防范措施,穿长筒弹力袜就是一种很好的方法,可帮助血液进入较大且较深处的静脉。

保持理想体重,可减少静脉曲张的机会;避免紧身衣物,穿医用弹力袜,以免使血液聚积在腿部;小心食用避孕药,某些避孕药可能引起这种问题。';
$out=keylink($str,$link,1); //$str 原始字符 $link,替换链接数组, 3替换次数
echo $out;
function _sortDesc($a, $b) {
return (strlen($a[0]) }
function keylink($str,$link,$count=1)
{
$linkDefs = $link;
$linkMap = array();
foreach($linkDefs as $row) {
$linkMap[] = explode(',', $row);
}

foreach($linkMap as $row) {
$str = preg_replace('/(\s*)('.$row[0].')(\s*)/sui', '${2}', $str);
}

usort($linkMap, '_sortDesc');

$tmpKwds = array();

foreach($linkMap as $i=>$row) {
list($kwd, $url) = $row;
for($j=$i+1; $j$subKwd = $linkMap[$j][0];
//如果包含其他关键字,暂时替换成其他字符串
if(strpos($kwd, $subKwd) !== false) {
$tmpKwd = '{'.md5($subKwd).'}';
$kwd = str_replace($subKwd, $tmpKwd, $kwd);
$tmpKwds[$tmpKwd] = $subKwd;
}
}
//把文字替换成链接
$str = preg_replace('/('.$row[0].')/sui', ''.$kwd.'', $str, $count);
}

//把代替子关键字的字符串替换回来
foreach($tmpKwds as $tmp=>$kwd) {
$str = str_replace($tmp, $kwd, $str);
}
return $str;
}
?>

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.