You need to get a domain from the url form (you need to get while this option is also possible that will be (you need to get or http: // (you need to get and even this (you need to get And in general, not necessarily google domain will be, and maybe yandex and vasya, and generally whatever.


 parse_url($url, PHP_URL_HOST); 

In general, I am talking about the fact that I need to get a main domain name with a domain zone. Domain zones are of the first level and the second: .ru and, .com and, and so on.

That is, so let's say, there must be something like [.*\\.]{0,}(A-Za-z-А-Я-а-я][\\.]{1,2}) , where that in brackets, should parsitsya. Those. the information that is before the last one or two points should be parsed, as well as the fact that after this information there is a domain zone, but before if there were points before, the information in front of them is not parsed.

    1 answer 1

     $txt = 'Необходимо получить домен из url вида (нужно получить ) при этом возможен и такой вариант, что будет'; $pattern = '#(?<=\.|/|\s)[a-zA-Z0-9-]{2,61}\.[a-zA-Z]{2,3}(?=\s|/)#i'; preg_match_all($pattern,$txt,$matches); echo '<pre>'; print_r($matches); echo '</pre>'; 

    See what happens.

    • This is a bad decision, because it cuts wrong, if we take for example domains of a similar nature, then we will get as a result, although the main domain is Shnur