Regex Magic Parser v0.1


SUBMITTED BY: Guest

DATE: Oct. 23, 2013, 6:17 a.m.

FORMAT: PHP

SIZE: 2.0 kB

HITS: 976

  1. <?php
  2. /**
  3. * Your average simple parser tools
  4. * @author roop <roop@hakz.co>
  5. * @copyright 2013, Hakz Project, https://hakz.co
  6. * @package Option parser
  7. */
  8. class RegexTools {
  9. public static $return;
  10. public static $params;
  11. /**
  12. * Gets the keys and values from the <option> tag
  13. * @param array $params callback array values
  14. */
  15. public static function magic_parse($matches)
  16. {
  17. $return = self::$return;
  18. $params = self::$params;
  19. if ($return === 'array') {
  20. if ( isset($params['order']) && is_array($params['order']) ) {
  21. foreach( $params['order'] as $key => $val) {
  22. $data[$key] = $matches[$val];
  23. }
  24. }
  25. $data = json_encode($data);
  26. }
  27. if ($return === 'sql') {
  28. if ( isset($params['order']) && is_array($params['order']) ) {
  29. foreach( $params['order'] as $key => $val) {
  30. $columns[] = $key;
  31. $values[] = $matches[$val];
  32. }
  33. }
  34. if ( isset($columns) && is_array($columns) ) {
  35. $columns = implode("`, `", $columns);
  36. }
  37. if ( isset($values) && is_array($values) ) {
  38. $values = implode("', '", $values);
  39. }
  40. $data = "INSERT INTO `{$params['table']}` (`{$columns}`) VALUES ('{$values}');\n";
  41. }
  42. return $data;
  43. }
  44. }

comments powered by Disqus