You are here

public function RestrictIpService::cleanIpAddressInput in Restrict IP 8

Same name and namespace in other branches
  1. 8.2 src/Service/RestrictIpService.php \Drupal\restrict_ip\Service\RestrictIpService::cleanIpAddressInput()
  2. 3.x src/Service/RestrictIpService.php \Drupal\restrict_ip\Service\RestrictIpService::cleanIpAddressInput()

*

Overrides RestrictIpServiceInterface::cleanIpAddressInput

File

src/Service/RestrictIpService.php, line 151

Class

RestrictIpService

Namespace

Drupal\restrict_ip\Service

Code

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