Copy codeThe Code is as follows:
<? Php
$ Link = array (
Baidu, http://www.baidu.com /',
'Server software, http://s.jb51.net /',
'Feet home, http://www.jb51.net /',
);
$ Str = 'search for server software in Baidu and you will be able to go to the software provided by the foot home. <br/>
It has become a fashion to stop wearing stockings in summer, and even in autumn. <Br/>
Experts suggested that this fashion is not conducive to the beauty of legs. It is reported that the lack of exercise for a long time can easily lead to varicose veins, especially those who have been standing for a long time, it is easy to cause the expansion, extension of the lower extremity vein or venous valve damage and even the onset of disease. The specific manifestation is the leg swelling, the lower extremity vein is like an e-like bending or nodules into a group, skin purple, especially the ankle and the inside of the calf is more serious. <Br/>
Experts pointed out that people who have been standing for work for a long time have more or less the performance of some varicose veins of the lower extremity, but the severity is different. Varicose veins of the lower extremity are a type of disease that is troublesome to treat and requires serious surgery. Therefore, the best way is to prevent problems before they occur. When the symptoms are not obvious, take preventive measures, wearing a long hose is a good way to help the blood enter a large and deep vein. <Br/>
Maintain the ideal weight to reduce the chance of varicose veins; avoid tight clothing and medical elastic so to avoid blood accumulation in the legs; Be careful when taking birth control pills, some birth control pills may cause this problem. ';
$ Out = keylink ($ str, $ link, 1); // $ str original character $ link, replacing the link array, 3 replace 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 ('/(<a. *?> \ S *) ('. $ row [0].') (\ s * <\/a>)/sui', '$ {2}', $ str );
}
Usort ($ linkMap, '_ sortDesc ');
$ TmpKwds = array ();
Foreach ($ linkMap as $ I =>$ row ){
List ($ kwd, $ url) = $ row;
For ($ j = $ I + 1; $ j <count ($ linkMap); $ j ++ ){
$ SubKwd = $ linkMap [$ j] [0];
// If other keywords are included, 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',' <a href = "'. $ row [1]. '"target =" _ blank "> '. $ kwd. '</a>', $ str, $ count );
}
// Replace the string that replaces the subkeyword
Foreach ($ tmpKwds as $ tmp => $ kwd ){
$ Str = str_replace ($ tmp, $ kwd, $ str );
}
Return $ str;
}
?>