ItSolutionStuff.com

How to Extract All Email Addresses from String in PHP?

By Hardik Savani • May 14, 2024
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...

Tags: PHP
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Get HTML Tag Value in PHP?

Read Now →

PHP Generate QR Code using Google Chart API Example

Read Now →

PHP Array Get Previous Element from Current Key

Read Now →

PHP Explode Every Character into Array Example

Read Now →

How to Remove Last Element from Array in PHP?

Read Now →

PHP Curl PUT Request Example Code

Read Now →

How to Generate 4,6,8,10 Digit Random number in PHP?

Read Now →

How to Connect SSH using PHP?

Read Now →

PHP Import Excel File into MySQL Database Tutorial

Read Now →

Pixel Tracking Code with PHP Example

Read Now →

How to Find Day Name from Specific Date in PHP?

Read Now →