Freelance Web Designer in Dubai & SEO Expert in Kerala
01 / 01

Extract Email address from a string in PHP

Extract Email address from a string in PHP

Best tool to extract email addresses from text online.

Are you a marketing expert. Here is the best PHP tool to extract the email address from a paragraph data.

All you need to paste the details in the text area and the script will extract all the email address from the text area.

email extractor from data php code

<?php
// Check if the form is submitted
$emails = [];
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Get the textarea input
$text = $_POST['textarea_input'];

// Define the regex pattern for email addresses
$pattern = '/[a-z0-9_\-\+]+@[a-z0-9\-]+\.[a-z]{2,4}(\.[a-z]{2,4})?/i';

// Use preg_match_all to find all matches
preg_match_all($pattern, $text, $matches);

// Extract the email addresses
$emails = $matches[0];
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Extract Email Addresses</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>

<div class="container mt-5">
<h1 class="mb-4 text-center">Email Extractor</h1>
<div class="card">
<div class="card-body">
<form method="post" action="">
<div class="mb-3">
<label for="textarea_input" class="form-label">Enter text:</label>
<textarea class="form-control" name="textarea_input" id="textarea_input" rows="6"></textarea>
</div>
<button type="submit" class="btn btn-primary">Extract Emails</button>
</form>
</div>
</div>

<?php if ($_SERVER["REQUEST_METHOD"] == "POST"): ?>
<div class="mt-4">
<h3>Extracted Email Addresses:</h3>
<?php if (!empty($emails)): ?>
<ul class="list-group">
<?php foreach ($emails as $email): ?>
<li class="list-group-item"><?php echo htmlspecialchars($email); ?></li>
<?php endforeach; ?>
</ul>
<?php else: ?>
<div class="alert alert-warning mt-2" role="alert">
No email addresses found.
</div>
<?php endif; ?>
</div>
<?php endif; ?>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
by anvar
Published : Aug , 16

Post a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

WhatsApp Logo Chat