PHP function to replace internal links in articles PHP keyword replacement (including the function of shielding and restoring original links)

WBOY
Release: 2016-07-25 08:57:39
Original
1417 people have browsed it
  1. /*

  2. * PHP替换文章内链
  3. * by bbs.it-home.org
  4. */
  5. function _base64_encode($t,$str) {
  6. return $t.""".base64_encode($str).""";
  7. }
  8. function _base64_decode($t,$str) {
  9. return $t.""".base64_decode($str).""";
  10. }

  11. function _keylinks($txt, $replacenum = '',$link_mode = 1) {

  12. /* 屏蔽原始的 a */
  13. $replace_a = "_base64_encode('ori_a=','\0')";
  14. $replace1_a = "stripslashes(base64_decode('\1'))";
  15. $search_a = "/.*?/isxe";
  16. $search1_a = "/ori_a=(".*?")/isxe";
  17. $txt = preg_replace($search_a, $replace_a, $txt);

  18. /* 屏蔽alt title src */

  19. $search = "/(alts*=s*|titles*=s*|srcs*=s*) # find (["'])?(.*?) # find single or double quote
  20. (?(2)\2|s+?) # if quote found, match up to next matching
  21. # quote, otherwise match up to next space
  22. /isxe";
  23. $replace = "_base64_encode('\1','\3')";
  24. $replace1 = "_base64_decode('\1','\3')";
  25. $txt = preg_replace($search, $replace, $txt);
  26. echo $txt;
  27. echo "
    http://bbs.it-home.org/



    ";
  28. /*
  29. $keywords = $this->data['keywords'];
  30. if($keywords) $keywords = strpos(',',$keywords) === false ? explode(' ',$keywords) : explode(',',$keywords);
  31. if($link_mode && !empty($keywords)) {
  32. foreach($keywords as $keyword) {
  33. $linkdatas[] = $keyword;
  34. }
  35. } else {
  36. $linkdatas = getcache('keylink','commons');
  37. }
  38. if($linkdatas) {
  39. $word = $replacement = array();
  40. foreach($linkdatas as $v) {
  41. if($link_mode && $keywords) {
  42. $word1[] = '/'.preg_quote($v, '/').'/';
  43. $word2[] = $v;
  44. $replacement[] = ''.$v.'';
  45. } else {
  46. $word1[] = '/'.preg_quote($v[0], '/').'/';
  47. $word2[] = $v[0];
  48. $replacement[] = ''.$v[0].'';
  49. }
  50. }
  51. if($replacenum != '') {
  52. $txt = preg_replace($word1, $replacement, $txt, $replacenum);
  53. } else {
  54. $txt = str_replace($word2, $replacement, $txt);
  55. }
  56. }
  57. */
  58. /* 还原原始 a */
  59. $txt = preg_replace($search1_a, $replace1_a, $txt);
  60. /* 还原alt title src */
  61. $txt = preg_replace($search, $replace1, $txt);
  62. echo $txt;
  63. return $txt;
  64. }

  65. $con = "

      性生活过度伤害前列腺。和谐美满的性生活,是男女生理的天然需要,是夫妻感情的粘合剂之一,是夫妻生活必不少的重要组成部分。但是有此想法的夫妻可要注意了。因为做x爱时间并非越长越好,夫妻的性生活的和谐与美满也不由性xai时间的长短来决定。反而,超时性XZ爱,还会影响到夫妻的健康,甚至引发各种疾病。

  66. 性生活过度伤害前列腺

    ";

  67. _keylinks($con);

  68. ?>

复制代码


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!