title: PHP use of undefined constant error
body: <p>Using a great script to grab details from imdb, I would like to thank Fabian Beiner.</p>
  
  <p>Just one error i have encountered with it is:</p>
  
  <p>Use of undefined constant sys_get_temp_dir assumed 'sys_get_temp_dir' in '/path/to/directory' on line 49</p>
  
  <p>This is the complete script</p>
  
  <pre><code>&lt;?php
  /**
  * IMDB PHP Parser
  *
  * This class can be used to retrieve data from IMDB.com with PHP. This script will fail once in
  * a while, when IMDB changes *anything* on their HTML. Guys, it's time to provide an API!
  *
  * @link http://fabian-beiner.de
  * @copyright 2010 Fabian Beiner
  * @author Fabian Beiner (mail [AT] fabian-beiner [DOT] de)
  * @license MIT License
  *
  * @version 4.1 (February 1st, 2010)
  *
  */
  
  class IMDB {
      private $_sHeader = null;
      private $_sSource = null;
      private $_sUrl    = null;
      private $_sId     = null;
      public  $_bFound  = false;
      private $_oCookie = '/tmp/imdb-grabber-fb.tmp';
  
      const IMDB_CAST         = '#&lt;a href="/name/(\w+)/" onclick="\(new Image\(\)\)\.src=\'/rg/castlist/position-(\d|\d\d)/images/b\.gif\?link=/name/(\w+)/\';"&gt;(.*)&lt;/a&gt;#Ui';
      const IMDB_COUNTRY      = '#&lt;a href="/Sections/Countries/(\w+)/"&gt;#Ui';
      const IMDB_DIRECTOR     = '#&lt;a href="/name/(\w+)/" onclick="\(new Image\(\)\)\.src=\'/rg/directorlist/position-(\d|\d\d)/images/b.gif\?link=name/(\w+)/\';"&gt;(.*)&lt;/a&gt;&lt;br/&gt;#Ui';
      const IMDB_GENRE        = '#&lt;a href="/Sections/Genres/(\w+|\w+\-\w+)/"&gt;(\w+|\w+\-\w+)&lt;/a&gt;#Ui';
      const IMDB_MPAA         = '#&lt;h5&gt;&lt;a href="/mpaa"&gt;MPAA&lt;/a&gt;:&lt;/h5&gt;\s*&lt;div class="info-content"&gt;\s*(.*)\s*&lt;/div&gt;#Ui';
      const IMDB_PLOT         = '#&lt;h5&gt;Plot:&lt;/h5&gt;\s*&lt;div class="info-content"&gt;\s*(.*)\s*&lt;a#Ui';
      const IMDB_POSTER       = '#&lt;a name="poster" href="(.*)" title="(.*)"&gt;&lt;img border="0" alt="(.*)" title="(.*)" src="(.*)" /&gt;&lt;/a&gt;#Ui';
      const IMDB_RATING       = '#&lt;b&gt;(\d\.\d/10)&lt;/b&gt;#Ui';
      const IMDB_RELEASE_DATE = '#&lt;h5&gt;Release Date:&lt;/h5&gt;\s*\s*&lt;div class="info-content"&gt;\s*(.*) \((.*)\)#Ui';
      const IMDB_RUNTIME      = '#&lt;h5&gt;Runtime:&lt;/h5&gt;\s*&lt;div class="info-content"&gt;\s*(.*)\s*&lt;/div&gt;#Ui';
      const IMDB_SEARCH       = '#&lt;b&gt;Media from&amp;nbsp;&lt;a href="/title/tt(\d+)/"#i';
      const IMDB_TAGLINE      = '#&lt;h5&gt;Tagline:&lt;/h5&gt;\s*&lt;div class="info-content"&gt;\s*(.*)\s*&lt;/div&gt;#Ui';
      const IMDB_TITLE        = '#&lt;title&gt;(.*) \((.*)\)&lt;/title&gt;#Ui';
      const IMDB_URL          = '#http://(.*\.|.*)imdb.com/(t|T)itle(\?|/)(..\d+)#i';
      const IMDB_VOTES        = '#&amp;nbsp;&amp;nbsp;&lt;a href="ratings" class="tn15more"&gt;(.*) votes&lt;/a&gt;#Ui';
      const IMDB_WRITER       = '#&lt;a href="/name/(\w+)/" onclick="\(new Image\(\)\)\.src=\'/rg/writerlist/position-(\d|\d\d)/images/b\.gif\?link=name/(\w+)/\';"&gt;(.*)&lt;/a&gt;#Ui';
      const IMDB_REDIRECT     = '#Location: (.*)#';
  
      /**
       * Public constructor.
       *
       * @param string $sSearch
       */
      public function __construct($sSearch) {
          if (function_exists(sys_get_temp_dir)) {
              $this-&gt;_oCookie = tempnam(sys_get_temp_dir(), 'imdb');
          }
          $sUrl = $this-&gt;findUrl($sSearch);
          if ($sUrl) {
              $bFetch        = $this-&gt;fetchUrl($this-&gt;_sUrl);
              $this-&gt;_bFound = true;
          }
      }
  
      /**
       * Little REGEX helper.
       *
       * @param string $sRegex
       * @param string $sContent
       * @param int    $iIndex;
       */
      private function getMatch($sRegex, $sContent, $iIndex = 1) {
          preg_match($sRegex, $sContent, $aMatches);
          if ($iIndex &gt; count($aMatches)) return;
          if ($iIndex == null) {
              return $aMatches;
          }
          return $aMatches[(int)$iIndex];
      }
  
      /**
       * Little REGEX helper, I should find one that works for both... ;/
       *
       * @param string $sRegex
       * @param int    $iIndex;
       */
      private function getMatches($sRegex, $iIndex = null) {
          preg_match_all($sRegex, $this-&gt;_sSource, $aMatches);
          if ((int)$iIndex) return $aMatches[$iIndex];
          return $aMatches;
      }
  
      /**
       * Save an image.
       *
       * @param string $sUrl
       */
      private function saveImage($sUrl) {
          $sUrl   = trim($sUrl);
          $bolDir = false;
          if (!is_dir(getcwd() . '/posters')) {
              if (mkdir(getcwd() . '/posters', 0777)) {
                  $bolDir = true;
              }
          }
          $sFilename = getcwd() . '/posters/' . preg_replace("#[^0-9]#", "", basename($sUrl)) . '.jpg';
          if (file_exists($sFilename)) {
              return 'posters/' . basename($sFilename);
          }
          if (is_dir(getcwd() . '/posters') OR $bolDir) {
              if (function_exists('curl_init')) {
  
                  $oCurl = curl_init($sUrl);
                  curl_setopt_array($oCurl, array (
                                                  CURLOPT_VERBOSE =&gt; 0,
                                                  CURLOPT_HEADER =&gt; 0,
                                                  CURLOPT_RETURNTRANSFER =&gt; 1,
                                                  CURLOPT_TIMEOUT =&gt; 5,
                                                  CURLOPT_CONNECTTIMEOUT =&gt; 5,
                                                  CURLOPT_REFERER =&gt; $sUrl,
                                                  CURLOPT_BINARYTRANSFER =&gt; 1));
                  $sOutput = curl_exec($oCurl);
                  curl_close($oCurl);
                  $oFile = fopen($sFilename, 'x');
                  fwrite($oFile, $sOutput);
                  fclose($oFile);
                  return 'posters/' . basename($sFilename);
              } else {
                  $oImg = imagecreatefromjpeg($sUrl);
                  imagejpeg($oImg, $sFilename);
                  return 'posters/' . basename($sFilename);
              }
              return false;
          }
          return false;
      }
  
      /**
       * Find a valid Url out of the passed argument.
       *
       * @param string $sSearch
       */
      private function findUrl($sSearch) {
          $sSearch = trim($sSearch);
          if ($aUrl = $this-&gt;getMatch(self::IMDB_URL, $sSearch, 4)) {
              $this-&gt;_sId  = 'tt' . preg_replace('[^0-9]', '', $aUrl);
              $this-&gt;_sUrl = 'http://www.imdb.com/title/' . $this-&gt;_sId .'/';
              return true;
          } else {
              $sTemp    = 'http://www.imdb.com/find?s=all&amp;q=' . str_replace(' ', '+', $sSearch) . '&amp;x=0&amp;y=0';
              $bFetch   = $this-&gt;fetchUrl($sTemp);
              if( $this-&gt;isRedirect() ) {
                  return true;
              }
              else if ($bFetch) {
                  if ($strMatch = $this-&gt;getMatch(self::IMDB_SEARCH, $this-&gt;_sSource)) {
                      $this-&gt;_sUrl = 'http://www.imdb.com/title/tt' . $strMatch . '/';
                      unset($this-&gt;_sSource);
                      return true;
                  }
              }
          }
          return false;
      }
  
      /**
       * Find if result is redirected directly to exact movie.
       */
      private function isRedirect()
      {
          if ($strMatch = $this-&gt;getMatch(self::IMDB_REDIRECT, $this-&gt;_sHeader)) {
              $this-&gt;_sUrl = $strMatch;
              unset($this-&gt;_sSource);
              unset($this-&gt;_sHeader);
              return true;
          }
          return false;
      }
  
      /**
      * Fetch data from given Url.
      * Uses cURL if installed, otherwise falls back to file_get_contents.
      *
      * @param string $sUrl
      * @param int    $iTimeout;
      */
      private function fetchUrl($sUrl, $iTimeout = 15) {
          $sUrl = trim($sUrl);
          if (function_exists('curl_init')) {
              $oCurl = curl_init($sUrl);
              curl_setopt_array($oCurl, array (
                                              CURLOPT_VERBOSE =&gt; 0,
                                              CURLOPT_HEADER =&gt; 1,
                                              CURLOPT_FRESH_CONNECT =&gt; true,
                                              CURLOPT_RETURNTRANSFER =&gt; 1,
                                              CURLOPT_TIMEOUT =&gt; (int)$iTimeout,
                                              CURLOPT_CONNECTTIMEOUT =&gt; (int)$iTimeout,
                                              CURLOPT_REFERER =&gt; $sUrl,
                                              CURLOPT_FOLLOWLOCATION =&gt; 0,
                                              CURLOPT_COOKIEFILE =&gt; $this-&gt;_oCookie,
                                              CURLOPT_COOKIEJAR =&gt; $this-&gt;_oCookie,
                                              CURLOPT_USERAGENT =&gt; 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6'
                                              ));
              $sOutput = curl_exec($oCurl);
  
              if ($sOutput === false) {
                  return false;
              }
  
              $aInfo = curl_getinfo($oCurl);
              if ($aInfo['http_code'] != 200 &amp;&amp; $aInfo['http_code'] != 302) {
                  return false;
              }
              $sTmpHeader     = strpos($sOutput, "\r\n\r\n");
              $this-&gt;_sHeader = substr($sOutput, 0, $sTmpHeader);
              $this-&gt;_sSource = str_replace("\n", '', substr($sOutput, $sTmpHeader+1));
              curl_close($oCurl);
  
              return true;
          } else {
              $sOutput = @file_get_contents($sUrl, 0);
              if (strpos($http_response_header[0], '200') === false){
                  return false;
              }
              $this-&gt;_sSource = str_replace("\n", '', (string)$sOutput);
              return true;
          }
          return false;
      }
  
      /**
       * Returns the cast.
       */
      public function getCast($iOutput = null, $bMore = true) {
          if ($this-&gt;_sSource) {
              $sReturned = $this-&gt;getMatches(self::IMDB_CAST, 4);
              if (is_array($sReturned)) {
                  if ($iOutput) {
                      foreach ($sReturned as $i =&gt; $sName) {
                          if ($i &gt;= $iOutput) break;
                          $sReturn[] = $sName;
                      }
                      return implode(' / ', $sReturn) . (($bMore) ? '&amp;hellip;' : '');
                  }
                  return implode(' / ', $sReturned);
              }
              return $sReturned;
          }
          return 'n/A';
      }
  
      /**
       * Returns the cast as links.
       */
      public function getCastAsUrl($iOutput = null, $bMore = true) {
          if ($this-&gt;_sSource) {
              $sReturned1 = $this-&gt;getMatches(self::IMDB_CAST, 4);
              $sReturned2 = $this-&gt;getMatches(self::IMDB_CAST, 3);
              if (is_array($sReturned1)) {
                  if ($iOutput) {
                      foreach ($sReturned1 as $i =&gt; $sName) {
                          if ($i &gt;= $iOutput) break;
                          $aReturn[] = '&lt;a href="http://www.imdb.com/name/' . $sReturned2[$i] . '/"&gt;' . $sName . '&lt;/a&gt;';;
                      }
                      return implode(' / ', $aReturn) . (($bMore) ? '&amp;hellip;' : '');
                  }
                  return implode(' / ', $sReturned);
              }
              return '&lt;a href="http://www.imdb.com/name/' . $sReturned2 . '/"&gt;' . $sReturned1 . '&lt;/a&gt;';;
          }
          return 'n/A';
      }
  
      /**
       * Returns the countr(y|ies).
       */
      public function getCountry() {
          if ($this-&gt;_sSource) {
              $sReturned = $this-&gt;getMatches(self::IMDB_COUNTRY, 1);
              if (is_array($sReturned)) {
                  return implode(' / ', $sReturned);
              }
              return $sReturned;
          }
          return 'n/A';
      }
  
      /**
       * Returns the countr(y|ies) as link(s).
       */
      public function getCountryAsUrl() {
          if ($this-&gt;_sSource) {
              $sReturned = $this-&gt;getMatches(self::IMDB_COUNTRY, 1);
              if (is_array($sReturned)) {
                  foreach ($sReturned as $sCountry) {
                      $aReturn[] = '&lt;a href="http://www.imdb.com/Sections/Countries/' . $sCountry . '/"&gt;' . $sCountry . '&lt;/a&gt;';
                  }
                  return implode(' / ', $aReturn);
              }
              return '&lt;a href="http://www.imdb.com/Sections/Countries/' . $sReturned . '/"&gt;' . $sReturned . '&lt;/a&gt;';
          }
          return 'n/A';
      }
  
      /**
       * Returns the director(s).
       */
      public function getDirector() {
          if ($this-&gt;_sSource) {
              $sReturned = $this-&gt;getMatches(self::IMDB_DIRECTOR, 4);
              if (is_array($sReturned)) {
                  return implode(' / ', $sReturned);
              }
              return $sReturned;
          }
          return 'n/A';
      }
  
      /**
       * Returns the director(s) as link(s).
       */
      public function getDirectorAsUrl() {
          if ($this-&gt;_sSource) {
              $sReturned1 = $this-&gt;getMatches(self::IMDB_DIRECTOR, 4);
              $sReturned2 = $this-&gt;getMatches(self::IMDB_DIRECTOR, 1);
              if (is_array($sReturned1)) {
                  foreach ($sReturned1 as $i =&gt; $sDirector) {
                      $aReturn[] = '&lt;a href="http://www.imdb.com/name/' . $sReturned2[$i] . '/"&gt;' . $sDirector . '&lt;/a&gt;';
                  }
                  return implode(' / ', $aReturn);
              }
              return '&lt;a href="http://www.imdb.com/name/' . $sReturned2 . '/"&gt;' . $sReturned1 . '&lt;/a&gt;';
          }
          return 'n/A';
      }
  
      /**
       * Returns the genre(s).
       */
      public function getGenre() {
          if ($this-&gt;_sSource) {
              $sReturned = $this-&gt;getMatches(self::IMDB_GENRE, 1);
              if (is_array($sReturned)) {
                  return implode(' / ', $sReturned);
              }
              return $sReturned;
          }
          return 'n/A';
      }
  
      /**
       * Returns the genre(s) as link(s).
       */
      public function getGenreAsUrl() {
          if ($this-&gt;_sSource) {
              $sReturned = $this-&gt;getMatches(self::IMDB_GENRE, 1);
              if (is_array($sReturned)) {
                  foreach ($sReturned as $i =&gt; $sGenre) {
                      $aReturn[] = '&lt;a href="http://www.imdb.com/Sections/Genres/' . $sGenre . '/"&gt;' . $sGenre . '&lt;/a&gt;';
                  }
                  return implode(' / ', $aReturn);
              }
              return '&lt;a href="http://www.imdb.com/Sections/Genres/' . $sReturned . '/"&gt;' . $sReturned . '&lt;/a&gt;';
          }
          return 'n/A';
      }
  
      /**
       * Returns the mpaa.
       */
      public function getMpaa() {
          if ($this-&gt;_sSource) {
              return implode('' , $this-&gt;getMatches(self::IMDB_MPAA, 1));
          }
          return 'n/A';
      }
  
      /**
       * Returns the plot.
       */
      public function getPlot() {
          if ($this-&gt;_sSource) {
              return implode('' , $this-&gt;getMatches(self::IMDB_PLOT, 1));
          }
          return 'n/A';
      }
  
      /**
       * Download the poster, cache it and return the local path to the image.
       */
      public function getPoster() {
          if ($this-&gt;_sSource) {
              if ($sPoster = $this-&gt;saveImage(implode("", $this-&gt;getMatches(self::IMDB_POSTER, 5)), 'poster.jpg')) {
                  return $sPoster;
              }
              return implode('', $this-&gt;getMatches(self::IMDB_POSTER, 5));
          }
          return 'n/A';
      }
  
      /**
       * Returns the rating.
       */
      public function getRating() {
          if ($this-&gt;_sSource) {
              return implode('', $this-&gt;getMatches(self::IMDB_RATING, 1));
          }
          return 'n/A';
      }
  
      /**
       * Returns the release date.
       */
      public function getReleaseDate() {
          if ($this-&gt;_sSource) {
              return implode('', $this-&gt;getMatches(self::IMDB_RELEASE_DATE, 1));
          }
          return 'n/A';
      }
  
      /**
       * Returns the runtime of the current movie.
       */
      public function getRuntime() {
          if ($this-&gt;_sSource) {
              return implode('', $this-&gt;getMatches(self::IMDB_RUNTIME, 1));
          }
          return 'n/A';
      }
  
      /**
       * Returns the tagline.
       */
      public function getTagline() {
          if ($this-&gt;_sSource) {
              return implode('', $this-&gt;getMatches(self::IMDB_TAGLINE, 1));
          }
          return 'n/A';
      }
  
      /**
       * Get the release date of the current movie.
       */
      public function getTitle() {
          if ($this-&gt;_sSource) {
              return implode('', $this-&gt;getMatches(self::IMDB_TITLE, 1));
          }
          return 'n/A';
      }
  
      /**
       * Returns the url.
       */
      public function getUrl() {
          return $this-&gt;_sUrl;
      }
  
      /**
       * Get the votes of the current movie.
       */
      public function getVotes() {
          if ($this-&gt;_sSource) {
              return implode('', $this-&gt;getMatches(self::IMDB_VOTES, 1));
          }
          return 'n/A';
      }
  
      /**
       * Get the year of the current movie.
       */
      public function getYear() {
          if ($this-&gt;_sSource) {
              return implode('', $this-&gt;getMatches(self::IMDB_TITLE, 2));
          }
          return 'n/A';
      }
  
      /**
       * Returns the writer(s).
       */
      public function getWriter() {
          if ($this-&gt;_sSource) {
              $sReturned = $this-&gt;getMatches(self::IMDB_WRITER, 4);
              if (is_array($sReturned)) {
                  return implode(' / ', $sReturned);
              }
              return $sReturned;
          }
          return 'n/A';
      }
  
      /**
       * Returns the writer(s) as link(s).
       */
      public function getWriterAsUrl() {
          if ($this-&gt;_sSource) {
              $sReturned1 = $this-&gt;getMatches(self::IMDB_WRITER, 4);
              $sReturned2 = $this-&gt;getMatches(self::IMDB_WRITER, 1);
              if (is_array($sReturned1)) {
                  foreach ($sReturned1 as $i =&gt; $sWriter) {
                      $aReturn[] = '&lt;a href="http://www.imdb.com/name/' . $sReturned2[$i] . '/"&gt;' . $sWriter . '&lt;/a&gt;';
                  }
                  return implode(' / ', $aReturn);
              }
              return '&lt;a href="http://www.imdb.com/name/' . $sReturned2 . '/"&gt;' . $sReturned1 . '&lt;/a&gt;';
          }
          return 'n/A';
      }
  }
  ?&gt;
  </code></pre>