- substr: documentation ( source)
- in_array: documentation ( source)
<?php
function link2code($link) {
$arr = array('http:/', 'https:', 'ftp://', 'ftps:/');
If(in_array(substr($link,0,6), $arr)){
return "<a href=\"$link\">$link</a>";
} else {
echo('Please provide whole link with protocol part, for example: http://myawesomewebsite.com');
}
}
echo link2code("https://127.0.0.1");