title: PHP Scrape Article Excerpt like Readability
body: <p>I've seen <a href="https://stackoverflow.com/questions/3450764/php-extract-article-excerpt-from-a-page">this question</a>, but it doesn't really satisfy what I'm looking for. That question's answers were either: lift from the meta description tag, and the second was generating an excerpt for an article you already have the body from.</p>
  
  <p>What I want to do is actually get the first few sentences of an <em>article</em>, like Readability does. What't the best method for this? HTML Parsing? Here's what I'm currently using, but this is not very reliable.</p>
  
  <pre><code>function guessExcerpt($url) {
      $html = file_get_contents_curl($url);
  
      $doc = new DOMDocument();
      @$doc-&gt;loadHTML($html);
  
      $metas = $doc-&gt;getElementsByTagName('meta');
  
      for ($i = 0; $i &lt; $metas-&gt;length; $i++)
      {
          $meta = $metas-&gt;item($i);
          if($meta-&gt;getAttribute('name') == 'description')
              $description = $meta-&gt;getAttribute('content');
  
      }
  
      return $description;
  }
  
  function file_get_contents_curl($url) {
      $ch = curl_init();
  
      curl_setopt($ch, CURLOPT_HEADER, 0);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_TIMEOUT, 5);
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  
      $data = curl_exec($ch);
      curl_close($ch);
  
      return $data;
  }
  </code></pre>