PHP content crawler HTML, title, description

Viewed 23

I am getting the content of some websites in HTML source. About titles and description. works on: example.com/nice-photos/ doesn't work if HTML source only /nice-photos/ or /21321314/

my codes here:

    <?php
    if($_GET['link'])
    {
      $dt = fopen("content.txt","aw+");
      $link = $_GET['link'];
      $page = $_GET['page'];
      $total_page = $_GET["total_page"];
      if($page=="")
      {
          $page = 1;
      }
      else
      {
          $link = str_replace("1",$page,$link);
      }
      $source = urlCek($link);
      
      preg_match_all('@<a href="(.*?)">@si', $source, $links); // HTML range of links in category

      foreach ($links[1] as $value) { // $link[] Write the number between the parentheses and the number according to the actual link in the link range.
       $kn = urlCek($value);

        preg_match_all('@<meta property="og:title" content="(.*?)" />@si', $kn, $title); // HTML range specified for the title
        preg_match_all('@<meta property="og:description" content="(.*?)" />@si', $kn, $content); // HTML range specified for description
        $description = $content[1][0];
        if(strstr($description,'ALL RIGHTS RESERVED'))
        {
            $description = '';
        }
        fwrite($dt,$title[1][0]."\n".$description."\n{}\n");

      }

      $next = $page+1;
      if($next>$total_page)
      {
            echo 'done!!!';
      }
      else
      {
     echo 'It saved. Going to the next page <meta http-equiv="refresh" content="0;URL=index.php?page='.$next.'&link='.$_GET["link"].'&total_page='.$_GET["total_page"].'">';
      }
    }
  ?>
0 Answers
Related