Canadian Posted February 5, 2010 Share Posted February 5, 2010 I'm trying to collect a number from a form and test whether or not the number ends in 999. The book I'm using to learn PHP it uses the ereg() or eregi() functions for regular expressions. I've just learned that these were phased out in PHP 5.3 after receiving and error. I think I have to use preg_match now. Regardless, I'm having some trouble with the syntax. Maybe it changed with preg_match. My code and error is below... Thanks Number Entry Form (just a basic form)... <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <h1>Enter Your Lucky Number! Are You a Winner?</h1> <form action="entry_results.php" method="post"> <table border="0"> <tr> <td>Please Enter Your Favorite Number</td> <td><input type="text" name="entry" maxlength="13" size="13"></td> </tr> </table> <input type="submit" value="Submit" /> </form> </body> </html> Here is my Page that collects the $_POST variable and looks for a number ending in 999 (I'm using the $ sign at the end of the 999 in the preg_match() function because my books says this is how you look for a match at the end of a string using an ereg() function... <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <?php $entry = $_POST['entry']; if (preg_match('999$', $entry)) { echo "You are a winner!!!"; } else { echo "Sorry, better luck next time."; } ?> </body> </html> Here is my error... Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in /Applications/XAMPP/xamppfiles/htdocs/flocycling44php/iMillionz_test_files/entry_results.php on line 15 Sorry, better luck next time. Quote Link to comment https://forums.phpfreaks.com/topic/191019-eregi-to-preg_match-help/ Share on other sites More sharing options...
oni-kun Posted February 5, 2010 Share Posted February 5, 2010 Nonsensitive: preg_match('/999$/', $entry) Insensitive: preg_match('/999$/i', $entry) Quote Link to comment https://forums.phpfreaks.com/topic/191019-eregi-to-preg_match-help/#findComment-1007242 Share on other sites More sharing options...
scotmcc Posted February 5, 2010 Share Posted February 5, 2010 You need to use a regex format: <?php $entry = "1230999"; if (preg_match('/999$/', $entry)) { echo "You are a winner!!!"; } else { echo "Sorry, better luck next time."; } ?> See: http://us.php.net/manual/en/function.preg-match.php Quote Link to comment https://forums.phpfreaks.com/topic/191019-eregi-to-preg_match-help/#findComment-1007243 Share on other sites More sharing options...
Canadian Posted February 5, 2010 Author Share Posted February 5, 2010 Thanks a lot guys. I appreciate the help. Quote Link to comment https://forums.phpfreaks.com/topic/191019-eregi-to-preg_match-help/#findComment-1007247 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.