PHP function code to automatically add keyword links to articles_PHP tutorial

WBOY
Release: 2016-07-21 15:14:23
Original
741 people have browsed it

Copy code The code is as follows:

$link = array(
'Baidu, http:/ /www.baidu.com/',
'Server software,http://s.jb51.net/',
'Script home,http://www.jb51.net/',
);
$str = 'Search for server software in Baidu and you can find the software provided by Script House

It has become a fashion not to wear stockings in summer in recent years, even in autumn. No exception.

Experts point out that this fashion is not conducive to beautiful legs. It is reported that sitting and standing for long periods of time, lack of exercise and other reasons can easily lead to varicose veins. Especially for people who stand and work for a long time, it is easy to cause the veins of the lower limbs to expand and lengthen, or the vein valves to be damaged and even cause disease. The specific manifestations include swelling of the legs, veins in the lower limbs bending like earthworms or forming nodules, and the skin turns purple, especially on the inner side of the ankles and calves.

Experts point out that people who stand and work for a long time have more or less varicose veins in the lower limbs, but the severity varies. Varicose veins of the lower limbs are a troublesome disease to treat, and severe cases require surgery. Therefore, the best way is to nip it in the bud. When the symptoms are not obvious, take preventive measures. Wearing long elastic stockings is one way. Great way to help get blood into larger, deeper veins.

Maintaining an ideal weight can reduce the chance of varicose veins; avoid tight clothing and wear medical elastic stockings to avoid blood accumulation in the legs; be careful when taking birth control pills, some birth control pills may cause this question. ';
$out=keylink($str,$link,1); //$str original character $link, replacement link array, 3 replacement times
echo $out;
function _sortDesc($a , $b) {
return (strlen($a[0]) < strlen($b[0])) ? 1 : -1;
}
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 other keywords are included, temporarily replace them with other strings
if(strpos($kwd, $subKwd) !== false) {
$tmpKwd = '{'.md5($subKwd).'}' ;
$kwd = str_replace($subKwd, $tmpKwd, $kwd);
$tmpKwds[$tmpKwd] = $subKwd;
}
}
//Replace text with link
$str = preg_replace('/('.$row[0].')/sui', '' .$kwd.'', $str, $count);
}

//Replace the string that replaces the sub-keyword back
foreach($tmpKwds as $ tmp=>$kwd) {
$str = str_replace($tmp, $kwd, $str);
}
return $str;
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326261.htmlTechArticleCopy the code as follows: ?php $link = array( 'Baidu, http://www.baidu.com /', 'Server software, http://s.jb51.net/', 'Script home, http://www.jb51.net/', ); $str = 'Search in Baidu...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template