Skip to content

Instantly share code, notes, and snippets.

@phpfiddle
Created March 24, 2017 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phpfiddle/ec2bf7e5a8b27aa6c53890c01b08eed9 to your computer and use it in GitHub Desktop.
Save phpfiddle/ec2bf7e5a8b27aa6c53890c01b08eed9 to your computer and use it in GitHub Desktop.
[ Posted by Andrew Elliott ] match email2
<?php
/**
Finding an exact match in a text file using PHP AJAX jQuery form
http://stackoverflow.com/questions/15121403/finding-an-exact-match-in-a-text-file-using-php-ajax-jquery-form
*/
if(isset($_POST["email"])){
$email = $_POST['email'];
$emails = <<<emails
Bobby Brown bobby@somewhere.com
Guy Slim guy@somewhere.com
Slim Jim slim@somewhere.com
emails;
if (strpos($email,'@')) {
$match = preg_match("/\b{$email}\b/i", $emails );
if ( $match) {
echo "Found!";
}
else {
echo "Sorry, not found";
}
}
else {
echo "Sorry, not found";
}
}else {
?>
<html>
<body>
<form>
Email address:<input type="text" name="usr" id="usr" />
<input type="submit" id="submit" name="submit" value="Submit"></form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.3/jquery.min.js"></script>
<script type="text/javascript">
var $url = '<?php echo $_SERVER['PHP_SELF']; ?>';
$('#submit').click(function(e){
e.preventDefault();
var id = 3;
$.ajax({
url: '<?php echo $_SERVER['PHP_SELF']; ?>',
type: 'POST',
data: "email="+ usr.value,
success: function(msg){
jQuery('body').append(msg);
},
error: function(){
alert("Error");
}
});
});
</script>
</body>
</html>
<?php
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment