Home > Backend Development > PHP Tutorial > How to add affiliate links in PHP_PHP tutorial

How to add affiliate links in PHP_PHP tutorial

WBOY
Release: 2016-07-13 09:44:08
Original
997 people have browsed it

How to add affiliate links in PHP

In order to optimize internal links, we need to add key links to the content. If we add affiliate links to the content, how to add it?

Method 1: Manually edit and add

Method 2: Use a program to output content without affecting the editing of background content.

The following is a method and example of PHP automatically adding affiliate links to article content:

Keylinks function method:

Parameter 1: Content to be processed

Parameter 2: Number of substitutions

Return result: 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 - focusing 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/1049990.htmlTechArticlePHP affiliate link adding method In order to optimize internal links, we need to add key links to the content. If the content is associated What about links? How to add them? Method 1: Manually edit and add...
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