Guest User

Untitled

a guest
Jan 22nd, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. function getMetas($link) {
  2. $str1 = file_get_contents($link);
  3.  
  4. if (strlen($str1)>0) {
  5. preg_match_all( '#<meta name="description".*content="([^"]+)">#siU', $str1, $description);
  6. if (count($description) > 1) {
  7. return $description[1];
  8. }
  9. if (!$description) {
  10. preg_match("/<s*p[^>]*>([^<]*)<s*/s*ps*>/", $str1, $re);
  11. $res = get_custom_excerpt($re[1]);
  12. echo $res;
  13.  
  14. }
  15.  
  16. }
  17. return '';
  18.  
  19.  
  20. }
  21.  
  22. <?php
  23. $html = '<div class="red">Jul 6, 2012</div>
  24. <div class="blue">12,889.40</div>
  25. <p>12,889.40</p>
  26. <div class="green">12,702.99</div>
  27. <div class="black">12,772.47</div>
  28. <div class="purple">967,600</div>
  29. <div class="grey">12,772.47</div>
  30. <div class="red">Jul 5, 2012</div>
  31. <div class="blue">12,941.85</div>
  32. <p class="yellow">12,961.30</p>
  33. <div class="green">12,852.24</div>
  34. <div class="black">12,896.67</div>
  35. <div class="purple">978,000</div>
  36. <div class="grey">12,896.67</div>';
  37.  
  38. preg_match("/<s*p[^>]*>([^<]*)<s*/s*ps*>/", $html, $re);
  39. $res = get_custom_excerpt($re[1]);
  40. echo $res;
  41.  
  42. function get_custom_excerpt($return, $option = 20, $sentance = false) {
  43. $marks = Array(".","!","?");
  44.  
  45. $return = strip_tags($return);
  46.  
  47. if($sentance == true) {
  48. $start = implode(" ", array_slice(preg_split("/s+/", $return), 0, $option ));
  49. $start .= ' ';
  50. $end = implode(" ", array_slice(preg_split("/s+/", $return), $option));
  51.  
  52. $cut = Array();
  53. foreach($marks AS $m => $mark){
  54. $mark = strpos($end, $mark);
  55. if($mark != false) $cut[$m] = $mark;
  56. }
  57.  
  58. if($cut[0] != "")
  59. $chop = min($cut);
  60. else
  61. $chop = $option;
  62. $rest = substr($end, 0, $chop);
  63.  
  64. $key = array_search($chop, $cut);
  65.  
  66. $return = $start.$rest;
  67.  
  68. }else{
  69. $return = implode(" ", array_slice(preg_split("/s+/", $return), 0, $option));
  70. }
  71. $return .= $marks[$key];
  72.  
  73. return $return;
  74. }
  75. ?>
  76.  
  77. <?php
  78. $matches;
  79. $html = "<p>some text</p>";
  80. preg_match_all("/(<p[^>]*>)(.*?SOMERESTRICTION.*?)(</p>)/"
  81. , $html
  82. , $matches
  83. , PREG_SET_ORDER
  84. );
  85. //matches
  86. print_r( $matches );
  87. ?>
Add Comment
Please, Sign In to add comment