<?php
/**
* Your average simple parser tools
* @author roop <roop@hakz.co>
* @copyright 2013, Hakz Project, https://hakz.co
* @package Option parser
*/
class RegexTools {
public static $return;
public static $params;
/**
* Gets the keys and values from the <option> tag
* @param array $params callback array values
*/
public static function magic_parse($matches)
{
$return = self::$return;
$params = self::$params;
if ($return === 'array') {
if ( isset($params['order']) && is_array($params['order']) ) {
foreach( $params['order'] as $key => $val) {
$data[$key] = $matches[$val];
}
}
$data = json_encode($data);
}
if ($return === 'sql') {
if ( isset($params['order']) && is_array($params['order']) ) {
foreach( $params['order'] as $key => $val) {
$columns[] = $key;
$values[] = $matches[$val];
}
}
if ( isset($columns) && is_array($columns) ) {
$columns = implode("`, `", $columns);
}
if ( isset($values) && is_array($values) ) {
$values = implode("', '", $values);
}
$data = "INSERT INTO `{$params['table']}` (`{$columns}`) VALUES ('{$values}');\n";
}
return $data;
}
}