How to Extract All Email Addresses from String in PHP?

By Hardik Savani September 30, 2021 Category : PHP

Hi,

This is a short guide on php find email in string. you can understand a concept of php find all email addresses in string. We will look at example of php check email string. you'll learn how to extract email address from text string php.

Here, i will give you simple example how to get email addresses from string content in php. so let's see both code and output as bellow:

Example:

index.php

<?php

$string = 'This email is [email protected] and company email is [email protected]';

$pattern = '/[a-z0-9_\-\+\.][email protected][a-z0-9\-]+\.([a-z]{2,4})(?:\.[a-z]{2})?/i';

preg_match_all($pattern, $string, $matches);

print_r($matches['0']);

Output:

Array

(

[0] => [email protected]

[1] => [email protected]

)

i hope it can help you...

Tags :