I'm looking for an efficient way to check a string for special characters other than checking every character in the string separately Could someone please help me out with this one?
if (preg_match ('/[^a-z]/i', $string_to_check)) { // The string contains characters other than a-z and A-Z } PHP:
Here is the function that I use to produce friendly URL's, hope it helps... function make_url_friendly($url) { $url = strtolower($url); $find = array(' ', '&', '\r\n', '\n', '/', '\\', '+'); $url = str_replace ($find, '-', $url); $find = array(' ', 'é', 'è', 'ë', 'ê'); $url = str_replace ($find, 'e', $url); $find = array(' ', 'ó', 'ò', 'ô', 'ö'); $url = str_replace ($find, 'o', $url); $find = array(' ', 'á', 'à ', 'â', 'ä'); $url = str_replace ($find, 'a', $url); $find = array(' ', 'Ã', 'ì', 'î', 'ï'); $url = str_replace ($find, 'i', $url); $find = array(' ', 'ú', 'ù', 'û', 'ü'); $url = str_replace ($find, 'u', $url); $find = array('/[^a-z0-9\-<>]/', '/[\-]+/', '/<[^>]*>/'); $repl = array('', '-', ''); $url = preg_replace ($find, $repl, $url); return $url; } Code (markup):
Thanks much, Was exactly what i was looking for. Works good with Explode!!! if (preg_match("/\\s/", $_POST['FirstName']) && is_null($_POST['LastName'])) { $fullname = explode(" ", $_POST['FirstName']); $firstname = $fullname[0]; $lastname= $fullname[1]; } else { $firstname = $_POST['FirstName']; $lastname = $_POST['LastName']; } Note, I put the && is_null lastname to make sure someone smart didn't put a space at the end of their first name causing it to trigger. and putting the last name blank.