Text files

It can be useful to both save and read data to and from text files. This is an easy task thanks to the SMTextFileWriter and SMTextFileReader classes.

Reading text files

$reader = new SMTextFileReader("feed.txt");
$content = $reader->ReadAll();
SMTextFileReader class

Function Return type Description
__construct($path:string)   Create instance of text reader class. Specify path to text file.
ReadAll() String Read the entire content of the text file.


Writing text files

$writer = new SMTextFileWriter("feed.xml");
$writer->Write("Hello world");
$writer->Close();
SMTextFileWriter class

Function Return type Description
__construct($path:string)
Create instance of text reader class. Specify path to text file. The file will be opened in Append Mode, meaning file will be created if it does not exist, and data will be appended to existing data.
__construct($path:string, $writeMode:SMTextFileWriteMode)   See description for __construct($path:string). Additionally the Write Mode may be specified. Also see SMTextFileWriteMode enum for more information about write mode.
Write($content:string)
Boolean
Write data to text file. Returns True on success, otherwise False. Remember to call Close() when done writing.
GetBytesWritten() Integer Get number of bytes written after calling Write(..) function.
Close() Boolean
Close file. Returns True on success, otherwise False.


SMTextFileWriteMode enum

Enum value Description
::$Create Creates file for writing. Will fail if file already exists.
::$Overwrite Creates new file, even though file already exists.
::$Append Creates file if not found. If file already exists, content will be read and appended to.