- array_map: documentation ( source)
- preg_match: documentation ( source)
- print_r: documentation ( source)
<?php
$domains[] = 'www.wp.pl';
$domains[] = 'http://www.onet.pl/plp/costam';
$domains[] = 'onet.pl';
$domains[] = 'https://redtube.com/porn';
print_r(array_map(function ($domain) {
preg_match('#(https?:\/\/)?(www\.)?([^\/]+)#', $domain, $matches);
return $matches[3] ?? null;
}, $domains));