soycharliente Posted June 11, 2007 Share Posted June 11, 2007 Warning: preg_match(): No ending delimiter '^' found in events.php on line 3 I have no idea what that means. <?php $checkEventMonth = preg_match("^[0-9]+$", $_GET["m"]); ?> Does that check that $_GET["m"] starts with a number and every character after the first is also a number? Quote Link to comment https://forums.phpfreaks.com/topic/55047-solved-preg_match-error/ Share on other sites More sharing options...
soycharliente Posted June 11, 2007 Author Share Posted June 11, 2007 If someone is going to post a tutorial about how to do something, then IT NEEDS TO BE RIGHT!!! LOL. Geez. (not anyone here. something i found on-line.) So I _think_ I fixed the error. But now all of my statements are coming up 0 when they are clearly 1. What am I doing wrong? <?php $checkEventMonth = preg_match("/^[0-9]+$/", $_GET["m"]); $checkEventDay = preg_match("/^[0-9]+$/", $_GET["d"]); $checkEventYear = preg_match("/^[0-9]+$/", $_GET["y"]); if(($eventMonth && $eventDay && $eventYear) == 1) { $eventMonth = $_GET["m"]; $eventDay = $_GET["d"]; $eventYear = $_GET["y"]; $eventDate = date("Y-m-d", mktime(0, 0, 0, $eventMonth, $eventDay, $eventYear)); /*dbconnect(); $query = "SELECT * FROM events WHERE theDate='$eventDate' ORDER BY title ASC"; $result = mysql_query($query) OR DIE("Unable to run event query."); dbclose();*/ $eventData = "Events for $eventMonth.$eventDay.$eventYear:\n"; } else { $eventData = "Not a valid date.\n"; } ?> <?php echo $eventData; ?> Quote Link to comment https://forums.phpfreaks.com/topic/55047-solved-preg_match-error/#findComment-272135 Share on other sites More sharing options...
TEENFRONT Posted June 11, 2007 Share Posted June 11, 2007 erm im not a regex guy but im not sure your doing it right. preg_match("/^[0-9]+$/", $_GET["m"]); to ME that looks like your only trying to see if "m" has a number between 0 and 9. AND you dont do anything with "$checkEventMonth". you just do the preg_match then leave the vars alone. Im guessing you may mean to do this ? if(($checkEventMonth && $checkEventDay && $checkEventYear) == 1) { Quote Link to comment https://forums.phpfreaks.com/topic/55047-solved-preg_match-error/#findComment-272150 Share on other sites More sharing options...
btherl Posted June 11, 2007 Share Posted June 11, 2007 to ME that looks like your only trying to see if "m" has a number between 0 and 9. Not quite, it checks that EVERY character is between 0 and 9. The ^ and $ anchor the start and end of the string, so the expression only matches if every character from the start to the end is 0-9. It also checks that there is at least one character (that's done by using + instead of * ) Quote Link to comment https://forums.phpfreaks.com/topic/55047-solved-preg_match-error/#findComment-272152 Share on other sites More sharing options...
ToonMariner Posted June 11, 2007 Share Posted June 11, 2007 It checks that the characters of $_GET['m'] are numeric which could be done like so <?php preg_match("/\d+/", $_GET["m"]); ?> Quote Link to comment https://forums.phpfreaks.com/topic/55047-solved-preg_match-error/#findComment-272187 Share on other sites More sharing options...
soycharliente Posted June 11, 2007 Author Share Posted June 11, 2007 How would you add on that it can't be empty? Like strlen() != 0. Or set how long it can be? Quote Link to comment https://forums.phpfreaks.com/topic/55047-solved-preg_match-error/#findComment-272244 Share on other sites More sharing options...
ToonMariner Posted June 11, 2007 Share Posted June 11, 2007 that is what the + is for - it means one or more times... Quote Link to comment https://forums.phpfreaks.com/topic/55047-solved-preg_match-error/#findComment-272675 Share on other sites More sharing options...
btherl Posted June 21, 2007 Share Posted June 21, 2007 Some examples: '|^[0-9]+|' => Match 1 or more digits (Doesn't match empty string) '|^[0-9]*|' => Match 0 or more digits (DOES match empty string) '|^[0-9]{5}|' => Match exactly 5 digits '|^[0-9]{3,5}|' => Match 3, 4 or 5 digits. '|^[0-9]?|' => Match 0 or 1 digits. Usually used to say "This character can be there or it can be missing, I don't care". Equivalent to {0,1} Quote Link to comment https://forums.phpfreaks.com/topic/55047-solved-preg_match-error/#findComment-278995 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.