For Internet programs, it is normal to optimize the keyword internal chain of text and text content. On the one hand, someone manually processes the keyword internal chain, which is too inefficient; on the other hand, the program automatically adds the internal chain, which saves time and facilitates management; today, we are discussing how to automatically add internal links to articles. Article inner chain: tieniu
For Internet programs, it is normal to optimize the keyword internal chain of text and text content. On the one hand, someone manually processes the keyword internal chain, which is too inefficient; on the other hand, the program automatically adds the internal chain, which saves time and facilitates management; today, we are discussing how to automatically add internal links to articles. Article internal link: tieniu http ://
For Internet programs, it is normal to optimize the keyword internal chain of text and text content. On the one hand, someone manually processes the keyword internal chain, which is too inefficient; on the other hand, the program automatically adds the internal chain, which saves time and facilitates management;
Today, we are discussing how to automatically add internal links to articles.
Article link:
Tieniu http://www.111.com
Li tieniu http://www.222.com
Li tieniu is tie Niu http://www.333.com
Li tieniu is iron niushan iron ox http://www.444.com
Text inner-link storage array
$ KeywordArr = array (0 => array ('title' => 'Li tieniu is iron niushan ', 'url' => 'HTTP: // www.444.com ',), 1 => array ('title' => 'Li tieniu is Iron Mountain ', 'url' => 'HTTP: // www.333.com ',), 2 => array ('title' => 'Li tie Niu ', 'url' => 'HTTP: // www.222.com ',), 3 => array ('title' => 'tie Niu ', 'url' => 'HTTP: // www.111.com ',),);
Article body:
This is an example of the internal link keyword below. Iron Niu lieimei female, Li tieniu like to have an emotional life. Iron Ox is also a ox, iron ox is like drinking, and sister is fond of boxing and fitness. Li tie Niu is also a ox, iron ox is Li tie Niu, and Li tie Niu is iron ox of iron ox. Niu.
Replaced body html
This is an example of the internal link keyword below.TieniuBeauty girl,Li tieniuI like an emotional life.TieniuIt's also a cow. Iron Ox enjoys drinking, and her sister enjoys boxing and fitness,Li tieniuIt's also a cow. The iron ox in tienishan is Li tieniu,Li tiiniu is an iiniu from iron niushan.. Niu.
Therefore, we cannot use regular replacement for the keywords that we want to combine long tails and short tails. We need to use regular matching. For processing functions, see
// Function keylink ($ content) {// $ keywordArr represents our keyword dictionary $ keywordArr = array (0 => array ('title' => 'Li tieniu is iron ox of Iron Mountain ', 'url' => 'HTTP: // www.444.com ',), 1 => array ('title' => 'Li tieniu is Iron Mountain', 'url' => 'HTTP: // www.333.com ',), 2 => array ('title' => 'Li tie Niu', 'url' => 'HTTP: // www.222.com ',), 3 => array ('title' => 'tie Niu ', '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 ('\'(?! (<.*?) | ($ Quote .')(?! ([^ <>] *?)>) | ([^>] *?) | ([^>] *?) \ 'Si', '$ v ['url'].' "target =" _ blank ">'. $ V ['title'].'', $ Data, 1); // number 1 indicates the replacement frequency in the regular expression. if ($ data = '') $ data = $ content ;} return $ data ;}
If the processing is not good, there will be a tragedy of Inner-chain nested inner-chain errors. Cause of the tragedy of the error: You can try DEDECMS. The DEDECMS internal chain has the problem of inner chain nested with the short tail keyword and long tail keyword.