function isOrderBy($orderBy) { // Strip leading/trailing spaces $orderBy = trim($orderBy); // Regular expression to match valid ORDER BY clauses $pattern = '/^ORDER\s+BY\s+(\w+\s+(ASC|DESC)\s*(,\s*\w+\s+(ASC|DESC)\s*)*)$/i'; return preg_match($pattern, $orderBy); }
isOrderBy('ORDER BY Name ASC'); // Returns 1 (true) isOrderBy('order by id desc, name asc'); // Returns 1 (true) isOrderBy('order by Name'); // Returns 0 (false) isOrderBy('ORDER BY Name, Age DESC'); // Returns 1 (true)This function is not a part of any package or library, it is a standalone function that can be used within any PHP project.