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

Developments:

 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 .ru.com, .com and .com.am, 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 Π²ΠΈΠ΄Π° http://test.google.ru/ (Π½ΡƒΠΆΠ½ΠΎ ΠΏΠΎΠ»ΡƒΡ‡ΠΈΡ‚ΡŒ google.ru ) ΠΏΡ€ΠΈ этом Π²ΠΎΠ·ΠΌΠΎΠΆΠ΅Π½ ΠΈ Ρ‚Π°ΠΊΠΎΠΉ Π²Π°Ρ€ΠΈΠ°Π½Ρ‚, Ρ‡Ρ‚ΠΎ Π±ΡƒΠ΄Π΅Ρ‚ http://google.ru/'; $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 test.22i.in.net, then we will get in.net as a result, although the main domain 22i.in.net is Shnur