How to add a PHP association link
In order to optimize the inner chain, we need to add the content of the key link, that content if the link is added, how to add it?
Method One: Manually edit the Add
Method Two: Use the program to output content, without affecting the background content editing.
Here's how PHP automatically adds an associated link method and an example to the article content:
Keylinks Function Method:
Parameter one: what to work on
Parameter two: number of replacements
Return results: Processed content
Header ("Content-type:text/html;charset=utf-8"); Set encoding
$linkdatas =array (
Array (' Front-end development ', ' http://blog.kgula.com '),
Array (' Front-end design ', ' http://blog.kgula.com '),
Array (' Web Front end ', ' http://blog.kgula.com '),
Array (' Front-end blog ', ' http://blog.kgula.com '),
);
echo "before replacing
";
echo $str = ' web front-end development-focus on website front-end design and Web user experience. Front-end development, focus on web front-end development, focus on Web user experience, focus on the latest and best front-end design resources and front-end development technology professional front-end blog ';
echo "
After replacement
";
echo $str =keylinks ($STR, 2);
/**
* Associated keyword substitution
* @param txt $string original string
* @param replacenum $int Number of replacements
* @return String returns strings
*/
function Keylinks ($txt, $replacenum = ") {
Global $linkdatas;
if ($linkdatas) {
$word = $replacement = Array ();
foreach ($linkdatas as $v) {
$word 1[] = '/(?! ()/s ';
$word 2[] = $v [0];
$replacement [] = '. $v [0]. '';
}
if ($replacenum! = ") {
$txt = Preg_replace ($word 1, $replacement, $txt, $replacenum);
} else {
$txt = Str_replace ($word 2, $replacement, $txt);
}
}
return $txt;
}
http://www.bkjia.com/PHPjc/1049990.html www.bkjia.com true http://www.bkjia.com/PHPjc/1049990.html techarticle PHP Associated Link Add method in order to optimize the inner chain, we need to add the content on the key link, that content if you add links, how to add it? Method One: Manually edit Add ...