Web Analytics Made Easy -
StatCounter Retrieving CIDR instead of hostname from array - CodingForum

Announcement

Collapse
No announcement yet.

Retrieving CIDR instead of hostname from array

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

    Comment


    • #3
      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. :-)

      Comment

      Working...
      X