Common codes for PHP affiliate links_PHP tutorial

WBOY
Release: 2016-07-21 15:15:17
Original
777 people have browsed it

Method 1: Manually edit and add
Method 2: Use a program to output content without affecting the editing of background content.

The following are methods and examples of PHP automatically adding associated links to article content:

Keylinks function method:
Parameter 1: Content to be processed
Parameter 2: Number of substitutions
Return result: processed content

Copy code The code is as follows:

header("Content- Type:text/html;charset=utf-8"); //Set encoding
$linkdatas=array(
array('front-end development', 'http://http://www.jb51.net '),
array('Front-end design', 'http://www.jb51.net'),
array('Web front-end', 'http://www.jb51.net'),
array('front-end blog', 'http://www.jb51.net'),
);
echo "before replacement
";
echo $str=' Web front-end development-focuses on website front-end design and Web user experience. Front-end development, a professional front-end blog focusing on Web front-end development, focusing on Web user experience, and focusing on the latest and best front-end design resources and front-end development technologies at home and abroad';
echo "
After replacement
";
echo $str=keylinks($str,2);
/**
* Related keyword replacement
* @param txt $string original string
* @param replacenum $int number of replacements
* @return string return string
*/
function keylinks($txt, $replacenum = '') {
global $linkdatas;
if ($linkdatas) {
$word = $replacement = array();
foreach ($linkdatas as $v) {
$word1[] = '/(?! ()/s';
$word2[] = $v [0];
$replacement[] = '' . $v[0] . ' ';
}
if ($replacenum != '') {
$txt = preg_replace($word1, $replacement, $txt, $replacenum);
} else {
$txt = str_replace($word2, $replacement, $txt);
}
}
return $txt;
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326148.htmlTechArticleMethod 1: Manual editing and addition Method 2: Use a program to implement it when outputting content without affecting the editing of background content . The following is a method and example of PHP automatically adding affiliate links to article content...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!