PHP - Moved: Can This Be Simplified?
This topic has been moved to MySQL Help.
http://www.phpfreaks.com/forums/index.php?topic=310389.0 Similar TutorialsSo, I am not very experienced with regexes, so I wanna ask if this code can be simplified with preg_match? It is code from my framework on what I am working for adding routes. To explain what is "default" and "MAP", here is example usage. And, callable is called via call_user_func_array if that helps.
// mapping routes $fw->route('home: GET|POST /', 'home'); // provide ReST interface by mapping HTTP requests to class method $fw->route('MAP /rest', 'some_class'); // default route (404 page) $fw->route('default', 'error');And this is route method. public function route($pattern, $callable) { $pattern = strtr($pattern,array(' '=>'')); if ($pattern == 'default') { $this->default_route = $callable; return $this; } $arr = explode('/', $pattern, 2); $method = $arr[0]; $route = '/'.$arr[1]; if (strpos($arr[0], ':') !== false) { $arr = explode(':', $arr[0], 2); $name = $arr[0]; $method = $arr[1]; } if ($method == 'MAP') { foreach ((explode('|', self::Methods)) as $method) { $this->route((isset($name)?$name.':':null).$method.$route, $callable.'->'.strtolower($method)); } return $this; } $this->routes[] = array($method, $route, $callable, isset($name)?$name:null); return $this; } Is there a more simplified way of doing a query conditional based on 2 possible options (or more?). If I remember right, there's an operator in javascript that does this simplification. right now I have: Code: [Select] if (isset($_POST['print_change']) && ($_POST['print_change'] = "no")){ $query_print = "UPDATE tbl_registration SET reg_hardcopied = '0' WHERE reg_id = '$id_printed'"; mysql_query($query_print); } elseif (isset($_POST['print_change']) && ($_POST['print_change'] = "yes")){ $query_print = "UPDATE tbl_registration SET reg_hardcopied = '1' WHERE reg_id = '$id_printed'"; mysql_query($query_print); } This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=316254.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=305825.0 This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=313579.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=346829.0 This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=356314.0 This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=325953.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=317014.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=328917.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=342987.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=328845.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=342919.0 This topic has been moved to PHP Freelancing. http://www.phpfreaks.com/forums/index.php?topic=349322.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=319767.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=328753.0 This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=353027.0 This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=314397.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=309960.0 This topic has been moved to PHP Installation & Configuration. http://www.phpfreaks.com/forums/index.php?topic=319595.0 |