Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Aug 2011
    Posts
    12
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Retrieving CIDR instead of hostname from array

    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.

    Code:
    $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;
    }

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    You're CIDR is the $key. You'll need to break it out when using a foreach:
    PHP Code:
    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.

  • Users who have thanked Fou-Lu for this post:

    afdah (08-25-2011)

  • #3
    New Coder
    Join Date
    Aug 2011
    Posts
    12
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    You're CIDR is the $key. You'll need to break it out when using a foreach:
    PHP Code:
    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. :-)


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •