当前位置: 首页>>代码示例>>PHP>>正文


PHP Reader::readString8方法代码示例

本文整理汇总了PHP中Reader::readString8方法的典型用法代码示例。如果您正苦于以下问题:PHP Reader::readString8方法的具体用法?PHP Reader::readString8怎么用?PHP Reader::readString8使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Reader的用法示例。


在下文中一共展示了Reader::readString8方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 /**
  * Constructs the ID3v1 class with given file. The file is not mandatory
  * argument and may be omitted. A new tag can be written to a file also by
  * giving the filename to the {@link #write} method of this class.
  *
  * @param string $filename The path to the file.
  */
 public function __construct($filename = false)
 {
     if (($this->_filename = $filename) === false || file_exists($filename) === false) {
         return;
     }
     $this->_reader = new Reader($filename);
     if ($this->_reader->getSize() < 128) {
         return;
     }
     $this->_reader->setOffset(-128);
     if ($this->_reader->read(3) != "TAG") {
         $this->_reader = false;
         // reset reader, see write
         return;
     }
     $this->_title = rtrim($this->_reader->readString8(30), " ");
     $this->_artist = rtrim($this->_reader->readString8(30), " ");
     $this->_album = rtrim($this->_reader->readString8(30), " ");
     $this->_year = $this->_reader->readString8(4);
     $this->_comment = rtrim($this->_reader->readString8(28), " ");
     /* ID3v1.1 support for tracks */
     $v11_null = $this->_reader->read(1);
     $v11_track = $this->_reader->read(1);
     if (ord($v11_null) == 0 && ord($v11_track) != 0) {
         $this->_track = ord($v11_track);
     } else {
         $this->_comment = rtrim($this->_comment . $v11_null . $v11_track, " ");
     }
     $this->_genre = $this->_reader->readInt8();
 }
开发者ID:AsteriaGamer,项目名称:steamdriven-kohana,代码行数:37,代码来源:ID3v1.php

示例2: getType

  /**
   * Returns the recognized MIME type/description of the given file. The type
   * is determined by the content using magic bytes characteristic for the
   * particular file type.
   *
   * If the type could not be found, the function returns the default value, or
   * <var>false</var>.
   *
   * @param string $filename The file path whose type to determine.
   * @param string $default  The default value.
   * @return string|false
   */
  public function getType($filename, $default = false)
  {
    $reader = new Reader($filename);

    $parentOffset = 0;
    foreach (preg_split("/^/m", $this->_magic) as $line) {
      $chunks = array();
      if (!preg_match("/^(?P<Dependant>>?)(?P<Byte>\d+)\s+(?P<MatchType>\S+)" .
                      "\s+(?P<MatchData>\S+)(?:\s+(?P<MIMEType>[a-z]+\/[a-z-" .
                      "0-9]+)?(?:\s+(?P<Description>.+))?)?$/", $line, $chunks))
        continue;
      
      if ($chunks["Dependant"]) {
        $reader->setOffset($parentOffset);
        $reader->skip($chunks["Byte"]);
      } else
        $reader->setOffset($parentOffset = $chunks["Byte"]);

      $matchType = strtolower($chunks["MatchType"]);
      $matchData = preg_replace
        (array("/\\\\ /", "/\\\\\\\\/", "/\\\\([0-7]{1,3})/e",
               "/\\\\x([0-9A-Fa-f]{1,2})/e", "/0x([0-9A-Fa-f]+)/e"),
         array(" ", "\\\\", "pack(\"H*\", base_convert(\"$1\", 8, 16));",
               "pack(\"H*\", \"$1\");", "hexdec(\"$1\");"),
         $chunks["MatchData"]);

      switch ($matchType) {
      case "byte":    // single character
        $data = $reader->readInt8();
        break;
      case "short":   // machine-order 16-bit integer
        $data = $reader->readInt16();
        break;
      case "long":    // machine-order 32-bit integer
        $data = $reader->readInt32();
        break;
      case "string":  // arbitrary-length string
        $data = $reader->readString8(strlen($matchData));
        break;
      case "date":    // long integer date (seconds since Unix epoch/1970)
        $data = $reader->readInt64BE();
        break;
      case "beshort": // big-endian 16-bit integer
        $data = $reader->readUInt16BE();
        break;
      case "belong":  // big-endian 32-bit integer
      case "bedate":  // big-endian 32-bit integer date
        $data = $reader->readUInt32BE();
        break;
      case "leshort": // little-endian 16-bit integer
        $data = $reader->readUInt16LE();
        break;
      case "lelong":  // little-endian 32-bit integer
      case "ledate":  // little-endian 32-bit integer date
        $data = $reader->readUInt32LE();
        break;
      default:
        $data = null;
        break;
      }

      if (strcmp($data, $matchData) == 0) {
        if (!empty($chunks["MIMEType"]))
          return $chunks["MIMEType"];
        if (!empty($chunks["Description"]))
          return $chunks["Description"];
      }
    }
    return $default;
  }
开发者ID:rtdean93,项目名称:therock,代码行数:82,代码来源:Magic.php

示例3: __construct

  /**
   * Constructs the ID3v1 class with given file. The file is not mandatory
   * argument and may be omitted. A new tag can be written to a file also by
   * giving the filename to the {@link #write} method of this class.
   *
   * @param string|Reader $filename The path to the file, file descriptor of an
   *                                opened file, or {@link Reader} instance.
   */
  public function __construct($filename = false)
  {
    if ($filename instanceof Reader)
      $this->_reader = &$filename;
    else if ((is_string($filename) && ($this->_filename = $filename) !== false &&
              file_exists($filename) !== false) ||
             (is_resource($filename) &&
              in_array(get_resource_type($filename), array("file", "stream"))))
      $this->_reader = new Reader($filename);
    else
      return;

    if ($this->_reader->getSize() < 128)
      throw new ID3_Exception("File does not contain ID3v1 tag");
    $this->_reader->setOffset(-128);
    if ($this->_reader->read(3) != "TAG") {
      $this->_reader = false; // reset reader, see write
      throw new ID3_Exception("File does not contain ID3v1 tag");
    }

    $this->_title = rtrim($this->_reader->readString8(30), " \0");
    $this->_artist = rtrim($this->_reader->readString8(30), " \0");
    $this->_album = rtrim($this->_reader->readString8(30), " \0");
    $this->_year = $this->_reader->readString8(4);
    $this->_comment = rtrim($this->_reader->readString8(28), " \0");

    /* ID3v1.1 support for tracks */
    $v11_null = $this->_reader->read(1);
    $v11_track = $this->_reader->read(1);
    if (ord($v11_null) == 0 && ord($v11_track) != 0)
      $this->_track = ord($v11_track);
    else
      $this->_comment = rtrim($this->_comment . $v11_null . $v11_track, " \0");

    $this->_genre = $this->_reader->readInt8();
  }
开发者ID:rtdean93,项目名称:therock,代码行数:44,代码来源:ID3v1.php

示例4: __construct

 /**
  * Constructs the ID3v2 class with given file and options. The options array
  * may also be given as the only parameter.
  *
  * The following options are currently recognized:
  *   o version -- The ID3v2 tag version to use in write operation. This option
  *     is automatically set when a tag is read from a file and defaults to 
  *     version 4.0 for tag write.
  *
  * @todo  Only limited subset of flags are processed.
  * @todo  Utilize the SEEK frame and search for a footer to find the tag
  * @todo  Utilize the LINK frame to fetch frames from other sources
  * @param string $filename The path to the file.
  * @param Array  $options  The options array.
  */
 public function __construct($filename = false, $options = array())
 {
     if (is_array($filename)) {
         $options = $filename;
         $filename = false;
     }
     $this->_options =& $options;
     if (($this->_filename = $filename) === false || file_exists($filename) === false) {
         $this->_header = new ID3_Header(null, $options);
     } else {
         $this->_reader = new Reader($filename);
         if ($this->_reader->readString8(3) != "ID3") {
             throw new ID3_Exception("File does not contain ID3v2 tag: " . $filename);
         }
         $this->_header = new ID3_Header($this->_reader, $options);
         if ($this->_header->getVersion() < 3 || $this->_header->getVersion() > 4) {
             throw new ID3_Exception("File does not contain ID3v2 tag of supported version: " . $filename);
         }
         if ($this->_header->hasFlag(ID3_Header::EXTENDEDHEADER)) {
             $this->_extendedHeader = new ID3_ExtendedHeader($this->_reader, $options);
         }
         if ($this->_header->hasFlag(ID3_Header::FOOTER)) {
             $this->_footer =& $this->_header;
         }
         // skip footer, and rather copy header
         while (true) {
             $offset = $this->_reader->getOffset();
             // Jump off the loop if we reached the end of the tag
             if ($offset - 10 >= $this->_header->getSize() - ($this->hasFooter() ? 10 : 0)) {
                 break;
             }
             // Jump off the loop if we reached the last frame
             if ($this->_reader->available() < 4 || Transform::fromUInt32BE($identifier = $this->_reader->read(4)) == 0) {
                 break;
             }
             $this->_reader->setOffset($offset);
             if (@fopen($filename = "ID3/Frame/" . strtoupper($identifier) . ".php", "r", true) !== false) {
                 require_once $filename;
             }
             if (class_exists($classname = "ID3_Frame_" . $identifier)) {
                 $frame = new $classname($this->_reader, $options);
             } else {
                 $frame = new ID3_Frame($this->_reader, $options);
             }
             if (!isset($this->_frames[$frame->getIdentifier()])) {
                 $this->_frames[$frame->getIdentifier()] = array();
             }
             $this->_frames[$frame->getIdentifier()][] = $frame;
         }
     }
 }
开发者ID:AsteriaGamer,项目名称:steamdriven-kohana,代码行数:66,代码来源:ID3v2.php

示例5: __construct

  /**
   * Constructs the ID3v2 class with given file and options. The options array
   * may also be given as the only parameter.
   *
   * The following options are currently recognized:
   *   o version -- The ID3v2 tag version to use in write operation. This option
   *     is automatically set when a tag is read from a file and defaults to
   *     version 4.0 for tag write.
   *   o readonly -- Indicates that the tag is read from a temporary file or
   *     another source it cannot be written back to. The tag can, however,
   *     still be written to another file.
   *
   * @todo  Only limited subset of flags are processed.
   * @todo  Utilize the SEEK frame and search for a footer to find the tag
   * @todo  Utilize the LINK frame to fetch frames from other sources
   * @param string|Reader $filename The path to the file, file descriptor of an
   *                                opened file, or {@link Reader} instance.
   * @param Array         $options  The options array.
   */
  public function __construct($filename = false, $options = array())
  {
    if (is_array($filename)) {
      $options = $filename;
      $filename = false;
    }

    $this->_options = &$options;
    if ($filename === false ||
        (is_string($filename) && file_exists($filename) === false) ||
        (is_resource($filename) && 
         in_array(get_resource_type($filename), array("file", "stream")))) {
      $this->_header = new ID3_Header(null, $options);
    } else {
      if (is_string($filename) && !isset($options["readonly"]))
        $this->_filename = $filename;
      if ($filename instanceof Reader)
        $this->_reader = &$filename;
      else
        $this->_reader = new Reader($filename);
      if ($this->_reader->readString8(3) != "ID3")
        throw new ID3_Exception("File does not contain ID3v2 tag");
      
      $startOffset = $this->_reader->getOffset();
      
      $this->_header = new ID3_Header($this->_reader, $options);
      if ($this->_header->getVersion() < 3 || $this->_header->getVersion() > 4)
        throw new ID3_Exception
          ("File does not contain ID3v2 tag of supported version");
      if ($this->_header->getVersion() < 4 &&
          $this->_header->hasFlag(ID3_Header::UNSYNCHRONISATION))
        throw new ID3_Exception
          ("Unsynchronisation not supported for this version of ID3v2 tag");
      unset($this->_options["unsyncronisation"]);
      if ($this->_header->hasFlag(ID3_Header::UNSYNCHRONISATION))
        $this->_options["unsyncronisation"] = true;
      if ($this->_header->hasFlag(ID3_Header::EXTENDEDHEADER))
        $this->_extendedHeader =
          new ID3_ExtendedHeader($this->_reader, $options);
      if ($this->_header->hasFlag(ID3_Header::FOOTER))
        $this->_footer = &$this->_header; // skip footer, and rather copy header

      while (true) {
        $offset = $this->_reader->getOffset();

        // Jump off the loop if we reached the end of the tag
        if ($offset - $startOffset - 10 >= $this->_header->getSize() -
            ($this->hasFooter() ? 10 : 0))
          break;

        // Jump off the loop if we reached the last frame
        if ($this->_reader->available() < 4 || Transform::fromUInt32BE
            ($identifier = $this->_reader->read(4)) == 0)
          break;
        $this->_reader->setOffset($offset);
        
        if (@fopen($filename = "ID3/Frame/" .
                   strtoupper($identifier) . ".php", "r", true) !== false)
          require_once($filename);
        if (class_exists($classname = "ID3_Frame_" . $identifier))
          $frame = new $classname($this->_reader, $options);
        else
          $frame = new ID3_Frame($this->_reader, $options);

        if (!isset($this->_frames[$frame->getIdentifier()]))
          $this->_frames[$frame->getIdentifier()] = array();
        $this->_frames[$frame->getIdentifier()][] = $frame;
      }
    }
  }
开发者ID:rtdean93,项目名称:therock,代码行数:89,代码来源:ID3v2.php


注:本文中的Reader::readString8方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。