Im trying to improve my programming (PHP) skills by working on the following challenge. The question that follows is not so much about a code problem nor am I asking for code but rather about the programming logic which should be applied.
(9,'zxvvgf@housecapades.com',0,0,1,1,0,1,1),
(10,'qwer@rogers.co.uk',1,0,0,1,0,0,1),
(11,'lorenIpsum@hotmail.com',0,0,0,1,0,0,1),
(12,'BarackObama@googlemail.co.uk',1,0,9,1,1,1,1),
(13,'DonaldTrump@courtesysupportteam.net',0,0,9,1,1,1,1),
(15,'Mcaine@mynet.com',1,0,9,1,1,1,1),
(16,'davestra_@hotmail.com',0,0,0,1,0,0,1),
(17,'lewisHamilton@carracing.co.uk',1,0,9,1,1,1,1)
Objective
Consider the following data dump above, I need to find a way to extract ONLY the email addresses which ends in .co.uk
and enter it into a db table. In this example there are only 2 email adresses ending in .co.uk namely BarackObama@googlemail.co.uk
and lewisHamilton@carracing.co.uk
The Prolem
Im having a tough time to figure out how to tackle this problem because:
- No (most) email addresses does not have the same amount of characters
- There is irrelevant data, more specifically numbers, between email addresses which should be ignored
My Logic / Psuedo Code
Find a common denominator in rows (I noticed the first column are integers increasing by one for each row) use this to assign values to variables
$min
and$max
(In this example$min=9
and$max=17
)Use the variables assigned above to loop over rows increasing loop by one with each iteration
Inside Loop Ignore all characters that are of type integrer
Use pregmatch to find an email address that ends with .co.uk
if found add to array
$couk_emails
else loop to next rowWhen loop ends upload array
$couk_emails
to DB table
Thats the logic / Psuedo I came up with however it feels flawed to me. I consider this to be quite a difficult challenge so I would love to hear from experienced programmers how they will tackle this type of problem
Note all Email addresses in this post are fictional / made up to the best of my knowledge