i want to validate a Text area where the user can insert only ip adresses, one per line. This is my simple php code when I press the button:
$text_area = strip_tags($_POST["text_area"]); $file = "ip_list.txt"; file_put_contents($file, $text_area);
This is the text area: Textarea
Thanks
Advertisement
Answer
Try this code
$ips = explode("n", str_replace("r", "", $_POST["text_area"])); foreach ($ips as $ip) { $isValidIp = filter_var($ip, FILTER_VALIDATE_IP); if ($isValidIp) { echo 'valid Ip'; } else { echo 'invalid Ip'; } }
References:
How do I check if a users input is a valid IP address or not?