Using getservbyname()
<?php $service = "ftp"; $port = getservbyname($service, 'tcp'); if($port === false) { die("Lookup of service '$service' failed.\n"); } else { echo "Service '$service' runs on port $port\n"; } ?>