$value) { if (in_array($key, $required)) { if (empty(trim($value))) { $error++; } else { //echo "$key is not empty ".strlen($value); } } } if ($error == 0) { return true; } else { return false; } } function magicInsert($tablename, $data) { global $db; $keys=''; $qm = ''; foreach ($data as $key => $value) { $keys .= $key . ','; $qm .= '?,'; } $keys = rtrim($keys, ','); $qm = rtrim($qm, ','); $sql = "INSERT INTO $tablename ( $keys ) VALUES ( $qm )"; $stmt = $db->prepare($sql); if ($stmt->execute(array_values($data))) { return true; } else { return false; } } function extractString($string, $start, $end) { $pos = stripos($string, $start); $str = substr($string, $pos); $str_two = substr($str, strlen($start)); $second_pos = stripos($str_two, $end); $str_three = substr($str_two, 0, $second_pos); $unit = trim($str_three); // remove whitespaces return $unit; } function match_route($r,$_routes){ $flag = 0; $params = []; foreach ($_routes as $route => $controller) { $flag = 0; if (strtolower($r) == $route) { return array('route' => $controller, 'params' => []); } if (substr_count($route, '/') == substr_count($r, '/')) { $data = explode('/', $r); $count = substr_count($route, '/'); $data2 = explode('/', $route); for ($i=0; $i <= $count; $i++) { if (strpos($data2[$i], '{') === false) { if ($data2[$i] != $data[$i]) { $flag = 1; break; } } else { $key = extractString($data2[$i], '{', '}'); $params[$key] = $data[$i]; } } if ($flag == 1) { continue; } return array('route' => $controller, 'params' => $params); } } } require_once(HOME . '/app/includes/user_functions.php');