You are here

function restrict_ip_sanitize_ip_list in Restrict IP 7.2

Sanitizes a list of IP addresses.

Helper function that takes a string containing IP addresses on separate lines, Strips them of any code comments, trims them, and turns them into a nice array of sanitized elements. Note that the elements may or may not be IP addresses and if validation is necessary, the array returned from this function should be validated.

Parameters

string $raw_ip_addresses: A newline separated list of IP addresses. This array may contain comments as well as IP addresses.

Return value

array An array of IP addresses (strings), one per element.

2 calls to restrict_ip_sanitize_ip_list()
restrict_ip_boot in ./restrict_ip.module
Implements hook_boot().
restrict_ip_settings_validate in includes/restrict_ip.pages.inc
Validation handler for restrict_ip_settings().

File

./restrict_ip.module, line 273
Holds hooks for the restrict_ip module.

Code

function restrict_ip_sanitize_ip_list($raw_ip_addresses) {
  $ip_addresses = trim($raw_ip_addresses);
  $ip_addresses = preg_replace('/(\\/\\/|#).+/', '', $ip_addresses);
  $ip_addresses = preg_replace('~/\\*([^*]|[\\r\\n]|(\\*+([^*/]|[\\r\\n])))*\\*+/~', '', $ip_addresses);
  $addresses = explode(PHP_EOL, $ip_addresses);
  $return = array();
  foreach ($addresses as $ip_address) {
    $trimmed = trim($ip_address);
    if (strlen($trimmed)) {
      $return[] = $trimmed;
    }
  }
  return $return;
}