Advertisement
gunawantw

latihan2.php

Jun 16th, 2019
479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.41 KB | None | 0 0
  1. <?php
  2.  
  3. function curl($url) {
  4.         $ch = curl_init();  // Initialising cURL
  5.         curl_setopt($ch, CURLOPT_URL, $url);    // Setting cURL's URL option with the $url variable passed into the function
  6.         curl_setopt($ch, CURLOPT_HEADER, false);
  7.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // Setting cURL's option to return the webpage data
  8.         //curl_setopt($ch, CURLOPT_SSLVERSION,3);
  9.         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  10.         $data = curl_exec($ch); // Executing the cURL request and assigning the returned data to the $data variable
  11.         curl_close($ch);    // Closing cURL
  12.         return $data;   // Returning the data from the function
  13. }
  14.  function scrape_between($data, $start, $end){
  15.         $data = stristr($data, $start); // Stripping all data from before $start
  16.         $data = substr($data, strlen($start));  // Stripping $start
  17.         $stop = stripos($data, $end);   // Getting the position of the $end of the data to scrape
  18.         $data = substr($data, 0, $stop);    // Stripping all data from after and including the $end of the data to scrape
  19.         return $data;   // Returning the scraped data from the function
  20.  }
  21.  
  22. $url = "https://alltop.com/viral/";
  23. $scraped_website = curl($url);
  24.  
  25. $datastart = "post-title" . chr(34) . ">";
  26. $dataend = "</h2>";
  27.  
  28. $content1 =  scrape_between($scraped_website,$datastart,$dataend);
  29.  
  30. echo $content1;
  31.  
  32. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement