Code for adding associated links to PHP

Source: Internet
Author: User
  1. /**
  2. * PHP Associated Links
  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 replacing
    ";
  12. 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 ';
  13. echo "
    After replacement
    ";
  14. echo $str =keylinks ($STR, 2);
  15. /**
  16. * Associated keyword substitution
  17. * @param txt $string original string
  18. * @param replacenum $int Number of replacements
  19. * @return String returns strings
  20. */
  21. function Keylinks ($txt, $replacenum = ") {
  22. Global $linkdatas;
  23. if ($linkdatas) {
  24. $word = $replacement = Array ();
  25. foreach ($linkdatas as $v) {
  26. $word 1[] = '/(?! ()/s ';
  27. $word 2[] = $v [0];
  28. $replacement [] = '. $v [0]. '';
  29. }
  30. if ($replacenum! = ") {
  31. $txt = Preg_replace ($word 1, $replacement, $txt, $replacenum);
  32. } else {
  33. $txt = Str_replace ($word 2, $replacement, $txt);
  34. }
  35. }
  36. return $txt;
  37. }
  38. ?>
Copy Code
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.