Jump to content

eregi TO preg_match help.


Canadian

Recommended Posts

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.