array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'de', ), 'this' => array ( 0 => 'splfileobject.ftruncate.php', 1 => 'SplFileObject::ftruncate', 2 => 'Truncates the file to a given length', ), 'up' => array ( 0 => 'class.splfileobject.php', 1 => 'SplFileObject', ), 'prev' => array ( 0 => 'splfileobject.ftell.php', 1 => 'SplFileObject::ftell', ), 'next' => array ( 0 => 'splfileobject.fwrite.php', 1 => 'SplFileObject::fwrite', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/spl/splfileobject/ftruncate.xml', ), 'history' => array ( ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); contributors($setup); ?>
(PHP 5 >= 5.1.0, PHP 7, PHP 8)
SplFileObject::ftruncate — Truncates the file to a given length
size
The size to truncate to.
Hinweis:
If
size
is larger than the file it is extended with null bytes.If
size
is smaller than the file, the extra data will be lost.
Beispiel #1 SplFileObject::ftruncate() example
<?php
// Create file containing "Hello World!"
$file = new SplFileObject("/tmp/ftruncate", "w+");
$file->fwrite("Hello World!");
// Truncate to 5 bytes
$file->ftruncate(5);
// Rewind and read data
$file->rewind();
echo $file->fgets();
?>
Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:
Hello