title: Need help converting my beautiful soup (Python) code to PHP
body: <p>I'm currently in the process of converting all of my beautiful soup code into PHP just to get used to PHP. However i've run into a bit of a problem, my php code will only work when the wiki page has 'External links' after the original run in the html (such as <a href="http://en.wikipedia.org/wiki/True_Detective_(TV_series)" rel="nofollow">True Detective Wiki</a>). I just found out that this won't always happen because there may not always be an 'External links' section. I was wondering if there was anyway to convert my beautiful soup code into php code using the same technique my beautiful soup code uses?</p>
  
  <pre><code>import requests, re
  from bs4 import BeautifulSoup
  
  def get_date(url):
      r = requests.get(url)
  
      soup = BeautifulSoup(r.content)
  
      date = soup.find_all("table", {"class": "infobox"})
  
      for item in date:
          dates = item.find_all("th")
          for item2 in dates:
              if item2.text == "Original run":
                  test2 = item2.find_next("td").text.encode("utf-8")
                  mysub = re.sub(r'\([^)]*\)', '', test2)
                  return my sub
  </code></pre>
  
  <p>and here is my php code currently</p>
  
  <pre><code>&lt;?php
  // Defining the basic cURL function
  function curl($url) {
      $ch = curl_init();  // Initialising cURL
      curl_setopt($ch, CURLOPT_URL, $url);    // Setting cURL's URL option with the $url variable passed into the function
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // Setting cURL's option to return the webpage data
      $data = curl_exec($ch); // Executing the cURL request and assigning the returned data to the $data variable
      curl_close($ch);    // Closing cURL
      return $data;   // Returning the data from the function
  }
  ?&gt;
  
  &lt;?php
  // Defining the basic scraping function
  function scrape_between($data, $start, $end){
      $data = stristr($data, $start); // Stripping all data from before $start
      $data = substr($data, strlen($start));  // Stripping $start
      $stop = stripos($data, $end);   // Getting the position of the $end of the data to scrape
      $data = substr($data, 0, $stop);    // Stripping all data from after and including the $end of the data to scrape
      return $data;   // Returning the scraped data from the function
  }
  ?&gt;
  
  &lt;?php
  $scraped_page = curl("http://en.wikipedia.org/wiki/The_Walking_Dead_(TV_series)");    // Downloading IMDB home page to variable $scraped_page
  $scraped_data = scrape_between($scraped_page, "&lt;table class=\"infobox vevent\" style=\"width:22em\"&gt;", "&lt;/table&gt;");   // Scraping downloaded dara in $scraped_page for content between &lt;title&gt; and &lt;/title&gt; tags
  $original_run = mb_substr($scraped_data, strpos($scraped_data, "Original run")-2, strpos($scraped_data, "External links") - strpos($scraped_data, "Original run")-2);
  echo $original_run;
  
  ?&gt;
  </code></pre>