How to Extract All Email Addresses from String in 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 hardik@gmail.com and company email is company@yahoo.com';
$pattern = '/[a-z0-9_\-\+\.]+@[a-z0-9\-]+\.([a-z]{2,4})(?:\.[a-z]{2})?/i';
preg_match_all($pattern, $string, $matches);
print_r($matches['0']);
Output:
Array
(
[0] => hardik@gmail.com
[1] => company@yahoo.com
)
i hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Get HTML Tag Value in PHP?
- PHP Generate QR Code using Google Chart API Example
- PHP Array Get Previous Element from Current Key
- PHP Explode Every Character into Array Example
- How to Remove Last Element from Array in PHP?
- PHP Curl PUT Request Example Code
- How to Generate 4,6,8,10 Digit Random number in PHP?
- How to Connect SSH using PHP?
- PHP Import Excel File into MySQL Database Tutorial
- Pixel Tracking Code with PHP Example
- How to Find Day Name from Specific Date in PHP?