How can PHP developers effectively handle and split multiple IP addresses entered through input fields for storage in MySQL?

To effectively handle and split multiple IP addresses entered through input fields for storage in MySQL, PHP developers can first sanitize the input to ensure it is in a valid format. Then, they can split the input by a delimiter (such as a comma) to separate each IP address. Finally, they can store each IP address in a separate row in the database table.

// Sanitize and split multiple IP addresses
$ipAddresses = $_POST['ip_addresses'];
$ipArray = array_map('trim', explode(',', $ipAddresses));

// Store IP addresses in MySQL
foreach($ipArray as $ip){
    $sql = "INSERT INTO ip_addresses (ip_address) VALUES ('$ip')";
    mysqli_query($conn, $sql);
}