W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
PHP 5 >= 5.3.0, PHP 7, PHP 8, PECL phar >= 2.0.0)
Phar::addFromString — 以字符串的形式添加一個文件到 phar 檔案
public Phar::addFromString(string $localName, string $contents): void
注意:此方法需要 將 php.ini 中的 phar.readonly 設(shè)為 0 以適合 Phar 對象. 否則, 將拋出PharException.
通過這個方法,任何字符串都可以被添加到 phar 檔案中。 文件將會以 localname 為路徑保存到檔案中。 這個方法與 ZipArchive::addFromString() 類似。
localName
文件保存到檔案時的路徑。
contents
要保存的文件內(nèi)容。
沒有返回值,失敗時會拋出異常。
示例 #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::addFile(), Phar::addFromString() and Phar::offsetSet() save a new phar archive each time they are called. If performance is a concern, Phar::buildFromDirectory() or Phar::buildFromIterator() should be used instead.
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: