downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

SplFileObject::fwrite> <SplFileObject::ftell
[edit] Last updated: Fri, 25 May 2012

view this page in

SplFileObject::ftruncate

(PHP 5 >= 5.1.0)

SplFileObject::ftruncateファイルを指定した長さに丸める

説明

public bool SplFileObject::ftruncate ( int $size )

ファイルを size バイトに丸めます。

パラメータ

size

丸めるサイズ。

注意:

size がファイルのサイズより大きい場合、ファイルは null バイトで拡大されます。

size がファイルのサイズより小さい場合、余分なデータは失われます。

返り値

成功した場合に TRUE を、失敗した場合に FALSE を返します。

例1 SplFileObject::ftruncate() の例

<?php
// "Hello World!" が格納されるファイルを作成する
$file = new SplFileObject("/tmp/ftruncate""w+");
$file->fwrite("Hello World!");

// 5 バイトに丸める
$file->ftruncate(5);

// 巻き戻してデータを読み出す
$file->rewind();
echo 
$file->fgets();
?>

上の例の出力は、 たとえば以下のようになります。

Hello

参考

  • ftruncate() - ファイルを指定した長さに丸める



add a note add a note User Contributed Notes SplFileObject::ftruncate
There are no user contributed notes for this page.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites