...

View Full Version : Retrieving CIDR instead of hostname from array



afdah
08-25-2011, 07:45 PM
Hi, I'm trying to retrive the CIDR values instead of hostname values from the below array. How do I fix my code?
Thank you.



$blacklist_hosting_provider = array( '103.4.16.0/22' => 'exigent.com.au', '103.4.8.0/21' => 'amazon.com' );

foreach ($blacklist_hosting_provider as $cidr) {
echo $cidr;
}

Fou-Lu
08-25-2011, 08:01 PM
You're CIDR is the $key. You'll need to break it out when using a foreach:


foreach ($blacklist_hosting_provider AS $cidr => $dns)


Although depending on what you are doing depends on if you can use it this way or not. These are just strings in PHP, you'll need to perform manual calculations in order to compare it to concrete addresses.

afdah
08-25-2011, 11:36 PM
You're CIDR is the $key. You'll need to break it out when using a foreach:


foreach ($blacklist_hosting_provider AS $cidr => $dns)


Although depending on what you are doing depends on if you can use it this way or not. These are just strings in PHP, you'll need to perform manual calculations in order to compare it to concrete addresses.

Thanks super mod. I manage to get the code to work with your help. :-)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum