Extract email addresses from a file using PHP and Regex?

Mujkanovic

Well-known member
Collaborate
Registered
Joined
Apr 24, 2016
Messages
424
Points
18
Hi everyone,

I have a small forum and I exported its database to a .sql file, I want to get all email addresses from this file using using PHP and Regex. How can I do this?

Here's sample data from my file.

(143, 2, '', 0, 'juicy', 'dbdf6d92aba8be1838c0ac48c4959622', '2007-04-16', '[email protected]', 0, '', '', '', '', '', 1, 0, 'Newbies', 0, 1164906590, 0, 1175865657, 1176753268, 0, 0, 10, 5, '0', 2, 0, 0, 0, 45112407, '', '0000-00-00', -1, -1, '203.144.143.10', 0, 1, '', 0, 0, 3, 17, 17, '$QU', '', 0, 0, 0, 0, 0, 0, '', 0, 250, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 1, '', 1326351663, 0, 0, 0, 1, 1, '', '', 0, '', 'vb', '', 0, 1, 0, 0, 0, 0, '0', 0, 0, 0, '', '', 0, NULL),
(144, 2, '', 0, 'y0g13', 'dbdf6d92aba8be1838c0ac48c4959622', '2006-11-30', '[email protected]', 0, '', '', '', '', '', 1, 0, 'Newbies', 0, 1164945192, 0, 1169369303, 1258059647, 0, 0, 10, 5, '-6', 2, 0, 0, 0, 45112407, '', '0000-00-00', -1, -1, '70.116.75.253', 0, 1, '', 0, 0, 3, 16, 15, '7\\e', '', 0, 0, 0, 0, 0, 0, '', 0, 250, 792, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 1, '', 1326351663, 0, 0, 0, 1, 1, '', '', 0, '', 'vb', '', 0, 1, 0, 0, 0, 0, '0', 0, 0, 0, '', '', 0, NULL),
(145, 3, '', 0, 'hromgrom', 'dbdf6d92aba8be1838c0ac48c4959622', '2006-12-01', '[email protected]', 0, '', '', '', '', '', 1, 0, 'Newbie', 0, 1164995162, 0, 1164995162, 1164995162, 0, 0, 10, 5, '-12', 2, 0, 0, 0, 45112407, '', '0000-00-00', -1, -1, '201.25.66.198', 0, 1, '', 0, 0, 3, 1, 1, '|\\4', '', 0, 0, 0, 0, 0, 0, '', 0, 250, 120, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 1, '', 1326351663, 0, 0, 0, 1, 1, '', '', 0, '', 'vb', '', 0, 1, 0, 0, 0, 0, '0', 0, 0, 0, '', '', 0, NULL),
(146, 3, '', 0, 'hromsgrom', 'dbdf6d92aba8be1838c0ac48c4959622', '2006-12-02', '[email protected]', 0, '', '', '', '', '', 1, 0, 'Newbie', 0, 1165086240, 0, 1165086240, 1165086240, 0, 0, 10, 5, '-12', 2, 0, 0, 0, 45112407, '', '0000-00-00', -1, -1, '211.187.0.36', 0, 1, '', 0, 0, 3, 1, 1, '\\H]', '', 0, 0, 0, 0, 0, 0, '', 0, 250, 111, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 1, '', 1326351663, 0, 0, 0, 1, 1, '', '', 0, '', 'vb', '', 0, 1, 0, 0, 0, 0, '0', 0, 0, 0, '', '', 0, NULL),
(147, 2, '', 0, 'SuperMonster', 'd34990fc023f66988367b945bbe0c78f', '2014-01-28', '[email protected]', 0, '', '', '', '', '', 1, 0, 'Newbies', 0, 1165170703, 0, 1370005182, 1390882966, 1390882530, 3, 10, 5, '0', 2, 0, 0, 0, 45112407, '', '0000-00-00', -1, -1, '24.244.178.106', 0, 1, '', 0, 0, 3, 17, 16, 'kh$+/[N\"eZ[Y%1\"t-c?ND6yr/5:~ma', '', 0, 6508322, 0, 0, 0, 0, '', 0, 250, 316, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 1, '', 1326351663, 0, 0, 0, 1, 1, '', '', 0, '', 'vb', '', 0, 1, 0, 0, 0, 1369580530, '0,1', 0, 0, 0, '', '', 0, NULL),
(148, 2, '', 0, 'subnetmasker', 'dbdf6d92aba8be1838c0ac48c4959622', '2006-12-03', '[email protected]', 0, '', '', '', '', '', 1, 0, 'Newbies', 0, 1165192884, 0, 1165192884, 1165192884, 0, 0, 10, 5, '0', 2, 0, 0, 0, 45112407, '', '0000-00-00', -1, -1, '85.98.191.155', 0, 1, '', 0, 0, 3, 17, 17, 'z7!', '', 0, 0, 0, 0, 0, 0, '', 0, 250, 258, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 1, '', 1326351663, 0, 0, 0, 1, 1, '', '', 0, '', 'vb', '', 0, 1, 0, 0, 0, 0, '0', 0, 0, 0, '', '', 0, NULL),
(149, 2, '', 0, 'subn3tmask3r', 'dbdf6d92aba8be1838c0ac48c4959622', '2006-12-03', '[email protected]', 0, '', '', '', '', '', 1, 0, 'Newbies', 0, 1165193746, 0, 1165195826, 1165195826, 0, 0, 10, 5, '0', 2, 0, 0, 0, 45112407, '', '0000-00-00', -1, -1, '85.98.85.99', 0, 1, '', 0, 0, 3, 17, 17, 'Tmh', '', 0, 0, 0, 0, 0, 0, '', 0, 250, 245, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 1, '', 1326351663, 0, 0, 0, 1, 1, '', '', 0, '', 'vb', '', 0, 1, 0, 0, 0, 0, '0', 0, 0, 0, '', '', 0, NULL),
(150, 2, '', 0, 'Murdock', 'dbdf6d92aba8be1838c0ac48c4959622', '2006-12-04', '[email protected]', 0, '', '', '', '', '', 1, 0, 'Newbies', 0, 1165256142, 0, 1166506600, 1166506600, 0, 0, 10, 5, '-8', 2, 0, 0, 0, 45112391, '', '0000-00-00', -1, -1, '68.124.57.179', 0, 1, '', 0, 0, 3, 17, 17, '2K$', '', 0, 0, 0, 0, 0, 0, '', 0, 250, 233, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 1, '', 0, 0, 0, 0, 1, 1, '', '', 0, '', 'vb', '', 0, 1, 0, 0, 0, 0, '0', 0, 0, 0, '', '', 0, NULL),
(151, 2, '', 0, 'jumpenjuhosaphat', 'dbdf6d92aba8be1838c0ac48c4959622', '2006-12-04', '[email protected]', 0, '', '', '', '', '', 1, 0, 'Newbies', 0, 1165256959, 0, 1165256959, 1165295159, 1165294834, 1, 10, 5, '-7', 2, 0, 0, 0, 45112391, '', '0000-00-00', -1, -1, '71.196.247.150', 1, 1, '', 0, 0, 3, 17, 17, '{Ki', '', 0, 0, 0, 0, 0, 0, '', 0, 250, 271, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 1, '', 0, 0, 0, 0, 1, 1, '', '', 0, '', 'vb', '', 0, 1, 0, 0, 0, 0, '0', 0, 0, 0, '', '', 0, NULL),
(152, 2, '', 0, 'skooz', 'dbdf6d92aba8be1838c0ac48c4959622', '2008-05-15', '[email protected]', 0, '', '', '', '', '', 1, 0, 'Newbies', 0, 1165257176, 0, 1175100969, 1179382014, 1175088670, 1, 10, 5, '0', 2, 0, 0, 0, 45112663, '', '0000-00-00', -1, -1, '83.59.210.90', 0, 1, '', 0, 0, 3, 17, 16, '|-i', '', 0, 0, 0, 0, 0, 0, '', 0, 250, 507, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 1, '', 1326351663, 0, 0, 0, 1, 1, '', '', 0, '', 'vb', '', 0, 1, 0, 0, 0, 0, '0', 0, 0, 0, '', '', 0, NULL),
(153, 16, '', 0, 'projectx', '6b397147d86e729c03c72346cde42b0e', '2014-06-18', '[email protected]', 0, '', '', '', '', '', 1, 0, 'Power Member', 0, 1165258717, 0, 1403381006, 1403435920, 1397069116, 642, 181, 12, '0', 1, 0, 1, 1, 45112663, '', '0000-00-00', -1, 1, '83.84.212.74', 0, 0, '', 0, 0, 2, 184, 0, ';hX:MKPcQ@n~1;#V`1.%NF}B.i*2-2', '', 0, 6746575, 0, 0, 0, 0, '', 0, 250, 2932, 3, 0, 0, 0, 0, 0, 0, 0, 0, 171, 227, 698, 100, 1, '', 0, 0, 2, 100, 1, 1, '4f8c752f2d6a74a3098dbe3697928c60', '', 0, '', 'vb', '', 0, 1, 0, 0, 0, 1346240529, '0,1', 0, 0, 0, '', '', 0, NULL),
(154, 2, '', 0, 'lesbizzz', 'dbdf6d92aba8be1838c0ac48c4959622', '2006-12-04', '[email protected]', 0, '', '', '', '', '', 1, 0, 'Newbies', 0, 1165259048, 0, 1165259048, 1165259478, 0, 0, 10, 5, '-12', 2, 0, 0, 0, 45112407, '', '0000-00-00', -1, -1, '212.13.99.14', 0, 1, '', 0, 0, 3, 17, 17, '(SS', '', 0, 0, 0, 0, 0, 0, '', 0, 250, 296, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 1, '', 1326351663, 0, 0, 0, 1, 1, '', '', 0, '', 'vb', '', 0, 1, 0, 0, 0, 0, '0', 0, 0, 0, '', '', 0, NULL),
(155, 3, '', 0, 'Dfrrttyg', 'dbdf6d92aba8be1838c0ac48c4959622', '2006-12-04', '[email protected]', 0, '', '', '', '', '', 1, 0, 'Newbie', 0, 1165261006, 0, 1165261006, 1165261006, 0, 0, 10, 5, '-12', 2, 0, 0, 0, 45112407, '', '0000-00-00', -1, -1, '203.144.144.163', 0, 1, '', 0, 0, 3, 1, 1, '~+S', '', 0, 0, 0, 0, 0, 0, '', 0, 250, 103, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 1, '', 1326351663, 0, 0, 0, 1, 1, '', '', 0, '', 'vb', '', 0, 1, 0, 0, 0, 0, '0', 0, 0, 0, '', '', 0, NULL),
(156, 16, '', 0, 'groverinri', '3694f710fb4d109095092580d435411a', '2013-07-05', '[email protected]', 0, '', '', '', '', '', 1, 0, 'Newbie', 0, 1165263082, 0, 1380684896, 1388975081, 1252209181, 48, 18, 5, '-5', 2, 0, 1, 0, 45112535, '', '0000-00-00', -1, 1, '199.94.169.247', 0, 0, '', 1226548223, 0, 3, 153, 7, 'O)]yh~sJga%gc4k26.Gj\\~~R>wvai3', '', 0, 1066117, 0, 0, 0, 0, '', 0, 252, 1019, 1, 0, 0, 0, 0, 0, 0, 0, 0, 34, 5, 9, 100, 1, '', 1332482464, 0, 0, 0, 1, 1, '', '', 0, '', 'vb', '', 0, 1, 0, 0, 0, 0, '0', 0, 0, 0, '', '', 0, NULL),
(157, 2, '', 0, 'Pittbug', 'dbdf6d92aba8be1838c0ac48c4959622', '2006-12-04', '[email protected]', 0, '', '', '', '', '', 1, 0, 'Newbies', 0, 1165265205, 0, 1165265205, 1165265855, 0, 0, 10, 5, '-5', 2, 0, 0, 0, 45112663, '', '0000-00-00', -1, -1, '68.167.230.77', 0, 1, '', 0, 0, 3, 17, 17, '^d,', '', 0, 0, 0, 0, 0, 0, '', 0, 250, 238, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 1, '', 1326351663, 0, 0, 0, 1, 1, '', '', 0, '', 'vb', '', 0, 1, 0, 0, 0, 0, '0', 0, 0, 0, '', '', 0, NULL),
(158, 2, '', 0, 'backslash', 'dbdf6d92aba8be1838c0ac48c4959622', '2006-12-04', '[email protected]', 0, '', '', '', '', '', 1, 0, 'Newbies', 0, 1165272084, 0, 1176732811, 1183300518, 1165272594, 1, 10, 5, '0', 2, 0, 0, 0, 45112407, '', '0000-00-00', -1, -1, '76.186.173.22', 0, 1, '', 0, 0, 3, 21, 18, 'wYO', '', 0, 0, 0, 0, 0, 0, '', 0, 250, 350, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 1, '', 1326351663, 0, 0, 0, 1, 1, '', '', 0, '', 'vb', '', 0, 1, 0, 0, 0, 0, '0', 0, 0, 0, '', '', 0, NULL),
(159, 3, '', 0, 'Albinagirl', 'dbdf6d92aba8be1838c0ac48c4959622', '2006-12-04', '[email protected]', 0, '', '', '', '', '', 1, 0, 'Newbie', 0, 1165273466, 0, 1165273466, 1165273466, 0, 0, 10, 5, '-12', 2, 0, 0, 0, 45112407, '', '0000-00-00', -1, -1, '195.189.45.72', 0, 1, '', 0, 0, 3, 1, 1, 'T<Y', '', 0, 0, 0, 0, 0, 0, '', 0, 250, 130, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 1, '', 1326351663, 0, 0, 0, 1, 1, '', '', 0, '', 'vb', '', 0, 1, 0, 0, 0, 0, '0', 0, 0, 0, '', '', 0, NULL),
(160, 2, '', 0, 'maximus', 'dbdf6d92aba8be1838c0ac48c4959622', '2010-05-04', '[email protected]', 0, '', '', '', '', '', 1, 0, 'Newbies', 0, 1165289061, 0, 1270978164, 1272977562, 1268964128, 1, 10, 5, '0', 2, 0, 0, 0, 45112407, '', '0000-00-00', -1, -1, '203.206.209.33', 0, 1, '', 0, 0, 3, 16, 16, 'HV+', '', 0, 1637234, 0, 0, 0, 0, '', 0, 250, 294, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 1, '', 1331017262, 0, 0, 0, 1, 1, '', '', 0, '', 'vb', '', 0, 1, 0, 0, 0, 0, '0', 0, 0, 0, '', '', 0, NULL),
I want to get emails on per line like this

 

TehParadox

Member
Registered
Joined
Dec 20, 2017
Messages
34
Points
8
Its not a big deal deal, you can do it very easily in excel too
if you want that do us for you, you can email of communicate with us on inbox i can do it for you..
 

Mujkanovic

Well-known member
Collaborate
Registered
Joined
Apr 24, 2016
Messages
424
Points
18
Mujkanovic
Awesome, you gave me a solution, I save my sql file to .csv file and open it with Excel
All emails are in a colum and I can easily get emails only.
Thank you so much!
 

fwh

Administrator
Staff Member
Joined
Dec 8, 2012
Messages
773
Points
63
@Mujkanovic

Here is the way using PHP and Regex to extract all emails from your data or text
You should use this way https://forumweb.hosting/19204-how-...sign-its-content-to-a-variable-using-php.html to read data from another file, after that, filter emails from the data that you are getting.

PHP:
<?php
if ($fh = fopen('filename.txt', 'r')) {
    while (!feof($fh)) {
        $line = fgets($fh);
        //echo $line;
    preg_match_all('~([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)~i',$line,$matches);
     //print out emails only
    echo $matches[1][0]."<br>";
    }
    fclose($fh);
}
?>
 
Older Threads
Recommended Threads
Replies
4
Views
1,781
Replies
15
Views
39,794
  • Locked
Replies
8
Views
7,648
Replies
10
Views
10,649
Similar Threads

Latest Hosting OffersNew Reviews

Sponsors

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top