The script is using user-friendly input format, which is actually XML template. This template can be generated dynamically (like dynamic php web-pages) and then passed to the TXT Generator (or stored for future use) - and TXT Generator will convert this XML template into TXT file.
TXT Generator has many features which will help you to make your generated TXT files look not as a bunch of lines of text: paragraphs with alignment, custom width, borders and page orientation; ordered and unordered lists; and even tables, with variable width, in-cell text alignment, table orientation on page.
This is very simple example of class usage:
<?
// UNCLUDING THE THE MAIN CLASS FILE
require_once "txt.generator/cl_txt_generator.inc";
// CREATING XML TEMPLATE
$xml_template = "<?xml version=\"1.0\"?>
<document>
<head>
<author>Paggard [paggard@paggard.com]</author>
<title>TXT Generator sample</title>
</head>
<body>
<align hor=\"center\">Hello World Sample</align>
<br />
<table border=\"1\" width=\"35%\" align=\"center\" text_align=\"center\">
<tr>
<td>Hello</td>
<td>World!</td>
</tr>
</table>
</body>
</document>
";
// MAIN CLASS CALL
$xml = new txt($xml_template);
// SAVING THE RESULT TEXT TO DISK
$fp = fopen("simple_usage.txt", "w");
fwrite($fp, $xml->get_result_file());
@fclose($fp);
?>
<?xml version="1.0"?> at the very beginning.
<Document> … </Document> element
<Document> … </Document><Align />
<Table border="0"> … </Table><align hor="center" />
<tr><td> </tr></td><tr><td> … </td></tr>
<!-- some comment -->
<?xml version="1.0"?>
<Document>
<Head>
<author>Author Text</author>
<title>Document Title</title>
<subject>Document Subject</subject>
<description>Document Description</description>
</Head>
...
</Document>
Document template may or may not have the header section. Header section is always enclosed in <Head> . . . </Head> tags and may have the following child elements:
<Author>Document Author</Author> - element to define the author of the document
<Title>Document Title</Title> - element to define the author of the document
<Subject>Document Subject</Subject> - element to define the subject of the document
<Description>Document Description</Description> - element to define the description of the document
All the above elements may or may not be present within the <Head> section of the document. If even one of the elements will be defined, the result text will have the header section containing the defined elements (Author, Title etc.). It will look like this:
-------------------------------------------------------------------------------- Author: Author Text Title: Document Title Subject: Document Subject Description: Document Description --------------------------------------------------------------------------------
<?xml version="1.0"?>
<Document>
...
<Body>
Main Text of the Document
</Body>
</Document>
Body of the document contains the main document layout. It should be always enclosed into <Body> ... </Body> tags. These elements may contain the following tags to describe text formatting:
"left", "right", "center" and "justify".
Border="1" - paragraph will have borders
Align="justify" - the text within paragraph will be justified (centered, right aligned etc.)
"left"
"right"
"center"
"justify"
Width="60%" - the width of the paragraph. Should always have '%' - the width of the paragraph will be calculated according to the specified percent value.
<list type="ordered"> <li> . . . </li> <li> . . . </li> </list>
Tag structure to define ordered or unordered lists. Type attribute may have the following values : "ordered" or "unordered"
<table width="50%" border="1" align="right" text_align="center">
<tr>
<td>Right aligned Table</td>
</tr>
<tr>
<td>Cell One</td>
<td>Cell Two</td>
</tr>
</table>
Tag structure to define tables. Table consists of rows and columns, there are no colspan and rowspan tags - instead of them you can specify exact number of cells in the ach row that you need. The row will be equally divided between all the cells.
<Table> element may have the following attributes:
Width="60%" - width of the table in percents, calculated on the page width
Border="1" - if is set to "1" - table has borders
Align="center" - horizontal position of the table on page
"left"
"right"
"center"
Text_align="left" - alignment of the text in table cells
<?xml version="1.0"?>
<document>
<head>
<author>Paggard [paggard@paggard.com]</author>
<title>TXT Generator sample</title>
<subject>To show the class in action</subject>
</head>
<body>
<align hor="center">
TXT Generator Class
</align>
<line />
<p align="right">One Ring to rule them all. One Ring to find them.<br />
One Ring to bring them all and in the darkness bind them.<br />
In the Land of Mordor where the Shadows lie.<br />
</p>
<table border="1" width="35%" align="center" text_align="center">
<tr>
<td>PHP</td>
<td>-></td>
<td>TXT</td>
</tr>
</table>
<p align="justify">TXT Generator is a PHP script, the younger member of the "Generators" family.
The script is aimed to creation of the plain text files (TXT). Certainly, there is no
use to "just create TXT file using PHP" - this is simple - so, TXT Generator is powered
by additional features in order to make it possible to create complicated layouts using
just plain text. Sometimes there is a need to stick to plain text - and here TXT Generator can help you.
</p>
<table border="1" width="100%" align="center">
<tr>
<td>This script is commercial and can not be distributed freely. </td>
</tr>
<tr>
<td>the price for the script is:</td>
<td>34 USD </td>
</tr>
</table>
<br />
Lists
<list type="ordered">
<li>Item 1</li>
<li>Item 2</li>
<list type="unordered">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
</list>
<li>Item 3</li>
<li>Item 4</li>
</list>
<br />
Tables
<table width="80%" border="1" align="right" text_align="center">
<tr>
<td>Right aligned Table</td>
</tr>
<tr>
<td>Cell One</td>
<td>Cell Two</td>
</tr>
</table>
</body>
</document>
© 2004. All Rights Reserved. This class is a commercial software, if you are interested in purchasing it - contact me.