5
I have the code:
function addhttp($url){
if(!preg_match('~^(http)s?://~i', $url)){
$url = 'http://'.$url;
}
return $url;
}
It adds HTTP if the given URL does not contain, but what I’m doubtful about is the question of ~ which has at the beginning and then at the end ~i . I wonder what this is for
Same goes for ~i ?
– Alisson Acioli
@Alissonacioli O
i
is a flag used to indicate that the comparison should be case-insensitive, that is to say, nay Differentiates uppercase and lowercase.– André Ribeiro
I get it... I tried to do it like this /^(http s)?:/// and made a mistake because of / . So use ~ ?
– Alisson Acioli
That’s the only way: /^(http)s?: //i
– Alisson Acioli
You need to escape the bar if it doesn’t understand that you closed and opened two regexs. @Alissonacioli
– rray
Understood. Thank you both very much!! @rray
– Alisson Acioli