Archive_Tar::extractInString() – extract one file and return it as a string


require_once 'Archive/Tar.php';

boolean extractInString ( string $path )


This method extracts the file identified by path from the archive and returns it as a string. It does not use temporary files.


  • string $path - the path of the file to extract

Return value

string - the content of the extracted file


Possible PEAR_Error values
Error code Error message Reason Solution
NULL " Unable to open in read mode archive " The file is exclusive locked by another application. Check for other applications working on the file. This can not be caused by a competive processing the archive with Archive_Tar
NULL " Invalid extractinstring mode mode " Implementation error Should not occur, please set up a bug report.
NULL " Error while opening name in write binary mode " The file could not be created. The file is maybe locked.
NULL " Extracted file filename does not have the correct file size filesize (size expected). Archive may be corrupted. " Read the message. Read the message.


This function can not be called statically.


Extract a file in a string

// tarname.tar with files :
//   dev/data/file.txt
//   dev/data/log.txt
//   dev/readme.txt

$tar_object = new Archive_Tar("tarname.tar");
$text = $tar_object->extractInString("dev/readme.txt");
echo $text;
list files and directories in archive (Previous) add a string in the archive (Next)
Last updated: Mon, 21 May 2018 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.