+ 10
Why foreach returns only the last value from an array correctly? Solved! Thanks to Anand Bhatnagar!
domains.txt contain two lines with: php.net sololearn.com So, I want ip next to every domain, but <?php $domains=file('domains.txt'); foreach($domains as $domain) { $ip = gethostbyname($domain); echo $domain. " " . $ip .'<br>'; } ?> the output is: php.net php.net sololearn.com 184.168.221.12 I need output: domain -> IP (not domain again) domain -> IP Any recommendation? Thank You SoloLearners! Maybe I have the problem how to get the domains from remote file to an array. to be continue https://www.sololearn.com/Discuss/717237/how-to-import-strings-from-domains-txt-to-an-array-in-the-index-php
3 ответов
+ 4
try with a trailing dot in php.net -
php.net.
sololearn.com
If you do a gethostbyname() and there is no trailing dot after a domainname that does not resolve, this domainname will ultimately be appended to the server-FQDN by nslookup.
(SOURCE- php.net)
note:
may be there is some problem with your file domaina.txt
because while trying this using array it works perfectly.
$domains= ["php.net", "sololearners.com"];
+ 9
Thank You Anand Bhatnagar!!!
I think there is no problem with the domains.txt.
I tried to use .,;"- behind the php.net and it is not working
But yes, when I manually create an array, it is OK:
$domains=['php.net', 'sololearn.com'];
foreach($domains as $domain)
{
$ip = gethostbyname($domain);
echo $domain. " " . $ip .'<br>';
}
?>
That's it!!!
php.net 72.52.91.14
sololearn.com 184.168.221.12
Maybe I have the problem how to get the domains from remote file to an array.
You are Great Anand, Thanks again!
0
my pleasure sir 😊