I would do the opposite. Instead of removing http://
or https://
and then adding it again, I would just check if the string starts with http://
or https://
, and add http://
only if it doesn’t.
Something like:
if($rr['site']) {
$url = preg_match('/^https?:\/\//', $rr['site']) ? $rr['site'] : 'http://'.$rr['site'];
echo '<a target="_blank" href="http://'.$url.'" class="">'.$url.'</a>';
}
1
solved Checking validity url in php [closed]