Phar::addFromString
(PHP 5 >= 5.3.0, PHP 7, PECL phar >= 2.0.0)
Phar::addFromString — 以字符串的形式添加一个文件到 phar 档案
说明
   public Phar::addFromString
    ( string 
  $localname
   , string $contents
   ) : voidNote:
此方法需要 将 php.ini 中的 phar.readonly 设为 0 以适合 Phar 对象. 否则, 将抛出PharException.
通过这个方法,任何字符串都可以被添加到 phar 档案中。 文件将会以 localname 为路径保存到档案中。 这个方法与 ZipArchive::addFromString() 类似。
参数
- 
localname
- 
      文件保存到档案时的路径。 
- 
contents
- 
      要保存的文件内容。 
返回值
没有返回值,失败时会抛出异常。
范例
Example #1 一个 Phar::addFromString() 示例
<?php
try {
    $a = new Phar('/path/to/phar.phar');
    $a->addFromString('path/to/file.txt', 'my simple file');
    $b = $a['path/to/file.txt']->getContent();
    // to add contents from a stream handle for large files, use offsetSet()
    $c = fopen('/path/to/hugefile.bin');
    $a['largefile.bin'] = $c;
    fclose($c);
} catch (Exception $e) {
    // handle errors here
}
?>
参见
- Phar::offsetSet() - Set the contents of an internal file to those of an external file
- PharData::addFromString() - Add a file from the filesystem to the tar/zip archive
- Phar::addFile() - 将一个文件从文件系统添加到 phar 档案中
- Phar::addEmptyDir() - 添加一个空目录到 phar 档案