Now let's cover some of the output methods that require a separate method. The first one is mode 1, which outputs an array of query strings containing all stored data. In some situations, such as when transferring data to a server you don't control, this will come in handy. function to_query_string() If we have some data stored then we first get all the keys. Nested loops are used to put together a numerical array where each element contains a query string that represents a row in the datastore. Looping through this array to create links in your application takes very little code. Mode 2 also creates query strings, but this time only the keys are included. This can be used to construct links to get specific items out of the datastore. This could be used to retrieve information about individual items in a shopping cart, for instance. function id_query() Next is mode 3, which outputs XSLT. This method accepts a single argument which is the path to a stylesheet, so process the output. A secondary method called get_xml is called first, to convert the information in the datastore to a simple XML format. function get_xml($source="blank") This method allows an optional argument that permits external conversion of an array of the appropriate format to be converted. This potentially includes an array coming from a database using some of the commonly used functions for retrieving records from MySQL or Postgres databases. The XML format that is produced is below. <?xml version="1.0" encoding="iso-8859-1?> The code for the from_xslt method is below. function from_xslt($file) You will need XSLT support in your PHP distribution to use this method. The choices are the PHP 4x Sablotron XSLT engine or the DOMXML extension. The DOM extension is no longer supported in PHP 5, a new XSL extension based on the libxslt library is used instead. This method could easily be modified if you are using the newest version. Mode 4 outputs just the XML format mentioned above. The last two output formats are CSV and configuration. The CSV output uses the get_csv method. There is one optional argument to the readout method that is passed on only to this method function readout($mode,$file="",$headers=true,$del=":") If headers is set to true, the first row in the csv file will be the keys for each item in each row of the datastore. If it is set to false then only the data will be included. This format can be viewed in Microsoft Excel or used as an import format for a database. function make_csv($headers,$source="blank") The final output format is the config format. It produces the configuration format mentioned before. The fourth argument of the readout method is the delimiter to be used between the key value pairs. function make_config($del) This format can be modified to fit different needs. The datastore itself can be used as a configuration system. The versatility is there if you need it.
blog comments powered by Disqus |
|
|
|
|
|
|
|