Home > Backend Development > PHP Tutorial > php code to add affiliate links

php code to add affiliate links

WBOY
Release: 2016-07-25 09:03:31
Original
925 people have browsed it
  1. /**
  2. *php affiliate link
  3. */
  4. header("Content-Type:text/html;charset=utf-8"); //Set encoding
  5. $linkdatas=array(
  6. array ('front-end development', 'http://http://bbs.it-home.org'),
  7. array('front-end design', 'http://bbs.it-home.org'),
  8. array ('web front-end', 'http://bbs.it-home.org'),
  9. array('front-end blog', 'http://bbs.it-home.org'),
  10. );
  11. echo " Before replacement
    ";
  12. echo $str='Web front-end development - Focus 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';
  13. echo "
    After replacement
    ";
  14. echo $str=keylinks($str,2);
  15. /**
  16. * Related keyword replacement
  17. * @param txt $string original string
  18. * @param replacenum $int number of replacements
  19. * @return string return string
  20. */
  21. function keylinks($txt, $replacenum = '') {
  22. global $linkdatas;
  23. if ($linkdatas) {
  24. $word = $replacement = array();
  25. foreach ($linkdatas as $v) {
  26. $word1[] = '/(?!()/s';
  27. $word2[] = $v[0];
  28. $replacement[] = '' . $v[0] . '';
  29. }
  30. if ($replacenum != '') {
  31. $ txt = preg_replace($word1, $replacement, $txt, $replacenum);
  32. } else {
  33. $txt = str_replace($word2, $replacement, $txt);
  34. }
  35. }
  36. return $txt;
  37. }
  38. ? >
Copy code


Related labels:
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