- parse_url: documentation ( source)
<?php
$links = array(
'test.com',
'http://test.net',
'https://secure.net',
'www.test.net',
'spotify:csad456ds4a6d',
'hey',
'hey.net'
);
foreach($links as $link) {
if(parse_url($link, PHP_URL_SCHEME) == '') {
$link = 'http://' . $link;
}
echo $link . PHP_EOL;
}