For the Internet program, it is one of the normal tasks to optimize the inner chain of text content. On the one hand, some people manually to deal with the chain of keywords, this efficiency is too low, on the other hand through the program automatically add internal chain, this is also easy to manage and convenient;
What we are discussing today is the way to automatically add inner chain to the article.
Articles within the chain:
Optimus Http://www.111.com
Li Tie Beef http://www.222.com
Li Tieyun is Optimus Http://www.333.com
Li Tieyun is the Optimus of Optimus Mountain Http://www.444.com
An array of text-in-chain storage
$keywordArr =Array ( ' title ' = ' Li Tieyun ' is the Optimus ' of Optimus Mountain ', ' url ' = '/' Www.444.com ',), array (' title ' = ' Li Tieyun ' is Optimus Mountain ', ' url ' = ' http://www.333.com ',), array ( ' title ' = ' li Tie cow ', ' url ' = ' http://www.222.com ', ', ' array (' title ' = ' + ' optimus ', ' url ' = Www.111.com ',),);
Article text:
This is my example of the following internal chain keywords ha. Optimus Beauty, Li Tieyun like to have a sentimental life. Optimus is also cattle, Optimus like to drink like a sister like boxing fitness, Li Tieyun is also cattle, Optimus Mountain Optimus is Li tie cattle, Li Tieyun is Optimus Mountain Optimus. New.
Replaced body HTML
This is my example of the following internal chain keywords ha.<ahref= "Http://www.111.com"Target= "_blank"><Strongclass= "Keylink">Optimus</Strong></a>Beauty Girl,<ahref= "Http://www.222.com"Target= "_blank"><Strongclass= "Keylink">Li Tie Beef</Strong></a>Like to have an emotional life.<ahref= "Http://www.111.com"Target= "_blank"><Strongclass= "Keylink">Optimus</Strong></a>Also cattle, Optimus like to drink like a sister like boxing fitness,<ahref= "Http://www.222.com"Target= "_blank"><Strongclass= "Keylink">Li Tie Beef</Strong></a>is also the Ox, Optimus Mountain's Optimus is the Li Tie Ox,<ahref= "Http://www.444.com"Target= "_blank"><Strongclass= "Keylink">Li Tieyun is the Optimus of Optimus Mountain.</Strong></a>。 New.
Then this long tail short tail want to combine the key words we use the conventional replacement processing is not possible, need to use the regular matching processing. Processing function See below
//Content Text Body contents functionKeylink ($content) { //$KEYWORDARR represent our Dictionary of keywords $KEYWORDARR=Array ( 0 =Array(' title ' = ' Li Tieyun ' is Optimus Mountain's Optimus ', ' url ' = ' http://www.444.com ',), 1 =Array(' title ' = ' Li Tieyun ' is Optimus Mountain ', ' url ' = ' http://www.333.com ',), 2 =Array(' title ' = ' li Tie ox ', ' url ' = ' http://www.222.com ',), 3 =Array(' title ' = ' optimus ', ' url ' = ' http://www.111.com ',),); if(!$KEYWORDARR)return $content; $data=$content; foreach($KEYWORDARR as $k=$v) { $quote=Str_replace(Array("‘", ‘-‘),Array("\‘", ‘\-‘),Preg_quote($v[' title '])); $data=Preg_replace(‘\‘(?! (<.*?) | (<a.*?) | (<strong.*?))) (‘.$quote.‘) (?! ([^<>]*?) >) | ([^>]*?</a>) | ([^>]*?</strong>)) \ ' Si ', ' <a href= '.$v[' url ']. ' " target= "_blank" ><strong class= "Keylink" > ".$v[' title ']. ' </strong></a> ',$data, 1);//The number 1 represents the replacement frequency that occurs in the regular if($data= = ")$data=$content; } return $data;}
If the processing is not good, there will be inner chain nested inside chain error tragedy. Wrong source of tragedy: We can try to use the inner chain of dedecms,dedecms short tail keyword and long tail keyword nested together with the wrong inner chain problem.
PHP article keywords similar short tail long tail inner chain replacement method Introduction