I have PHP script that fetches a list of IP-adresses from an URL, prepends and appends some text and linebreaks to it. This works well, except the source has an empty line at the end, and that makes a line without IP-adress. I need the script to ignore or delete that line, so that it is not generated.
<?php
$ipPage = file_get_contents('https://my.pingdom.com/probes/ipv4');
$ipList = explode("\n", $ipPage);
echo "/ip firewall address-list\n";
echo "remove [/ip firewall address-list find list=Pingdom]\n";
foreach($ipList as $ip) {
echo "add address=" . $ip . " list=Pingdom\n";
}
?>
You can see the result and the empty last line at https://novaram.dk/mikrotik.php