1. Go to this page and download the library: Download byjg/anydataset library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
byjg / anydataset example snippets
$dataset = new \ByJG\AnyDataset\Core\AnyDataset("example");
$iterator = $dataset->getIterator();
foreach ($iterator as $row) {
print $row->toArray();
}
$filter = new \ByJG\AnyDataset\Core\IteratorFilter();
$filter->addRelation("field1", \ByJG\AnyDataset\Core\Enum\Relation::EQUAL, 10);
$iterator2 = $dataset->getIterator($filter);
foreach ($iterator as $row) {
print_r($row->get("field1"));
}
$output = RowOutput::getInstance()
->addFormat("field1", "Test {field1}")
->addFormat("field2", "Showing {} and {field3}");
->addCustomFormat("field3", function ($row, $field, $value) {
// return the formatted output.
// $row: The row object with all values
// $field: The field has been processed
// $value: The field value
});
// This will output the field1 formatted:
echo $output->print($row, "field1");
// This will apply the format defintion to all fields at once:
$ouput->apply($row);
$validator = RowValidator::getInstance()
->xValidation("field4", '/\d{4}-\d{2}-\d{2}/')
->customValidation("field3", function($value) {
// Return any string containing the error message if validation FAILS
// otherwise, just return null and the valition will pass.
});
$validator->validate($row) // Will return an array with the error messages. Empty array if not errors.
namespace ByJG\AnyDataset\Core\Formatter;
interface FormatterInterface
{
/**
* Return the object in your original format, normally as object
*
* @return mixed
*/
public function raw();
/**
* Return the object transformed to string.
*
* @return string
*/
public function toText();
/**
* Save the contents to a file
*
* @param string $filename
* @return void
*/
public function saveToFile($filename);
}
$formatter = new XmlFormatter($anydataset->getIterator());
$formatter->raw(); // Return a DOM object
$formatter->toText(); // Return the XML as a text
$formatter->saveToFile("/path/to/file.xml"); // Save the XML Text to a file.
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.