playstat
asked on
Search and replace urls with email addresses
hi there
I have a list of urls in one text file and then some emails in another.
What im after is a way of comparing and finding the domain name of an email with the list of the urls in a text file
for example
url list
http://www.thisisadomain.com/?=23453
http://www.acooldomain.com/?=34234
http://noemailmatches.com/?=23454
hhp://ifonlyihadasportscar .com?=3423 4
then in the email list you would have something like this that matches that domain
admin@thisisadomain.com
support@acooldomain.com
contact@ifonlyihadasportsc ar.com
now if there are missing emails or it cannot find the right address for that matched domain just copy the original URL in its place.
So the final master file would be a combo of matched emails to domain and the urls that have no matches.
admin@thisisadomain.com
support@acooldomain.com
http://noemailmatches.com/?=23454 <-------------------- no matches from email list
contact@ifonlyihadasportsc ar.com
can you make sure the output is line by line
Best regards
I have a list of urls in one text file and then some emails in another.
What im after is a way of comparing and finding the domain name of an email with the list of the urls in a text file
for example
url list
http://www.thisisadomain.com/?=23453
http://www.acooldomain.com/?=34234
http://noemailmatches.com/?=23454
hhp://ifonlyihadasportscar
then in the email list you would have something like this that matches that domain
admin@thisisadomain.com
support@acooldomain.com
contact@ifonlyihadasportsc
now if there are missing emails or it cannot find the right address for that matched domain just copy the original URL in its place.
So the final master file would be a combo of matched emails to domain and the urls that have no matches.
admin@thisisadomain.com
support@acooldomain.com
http://noemailmatches.com/?=23454 <-------------------- no matches from email list
contact@ifonlyihadasportsc
can you make sure the output is line by line
Best regards
oops:
if (strpos($domain, $email) !== false) {
should be:
if (strpos($email, $domain) !== false) {
if (strpos($domain, $email) !== false) {
should be:
if (strpos($email, $domain) !== false) {
ASKER
it doesnt work
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
$data="http://www.thisisadomain.com/?=23453";
// get host name from URL
preg_match("/^(http:\/\/)?([^\/]+)/i",
"http://www.thisisadomain.com/?=23453", $matches);
$host = $matches[2];
// get last two segments of host name
preg_match("/[^\.\/]+\.[^\
echo "<br>domain name from URL : ".$matches[0]."\n";
$email = "admin@thisisadomain.com";
$str_pos=strpos($email,'@'
$domain_email=substr($emai
echo "<br><br><br>Domain Email : ".$domain_email;
if(strcmp($domain_email,$m
{
echo "<br>Matched";
$data = preg_replace('|\\b(http://[^\s)<]
echo "<br><br><br>Result :".$data;
}
else
{
echo "<br> Not Matched";
}
I have done it with an example, not the full code, but the main part of it. I think u know how to read from and write in to a text file. Customize this code according to your need.
$emails = file('emails.txt');
$output = fopen('out.txt', 'w');
foreach($urls as $url) {
if (preg_match('/http[s]?:\/\
$domain = $matches[2];
$out = '';
foreach($emails as $email) {
if (strpos($domain, $email) !== false) {
$out = $email;
break; //stop looking
}
}
if ($out = '') {
fwrite($output, "$url\n");
} else {
fwrite($output, "$out\n");
}
}
}
fclose($output);
Not tested, other than the regex, but that should be roughly what you need. Not the most efficient, but shouldn't be too slow.