Examples:
www.example.com -> example.com
search.example.com -> example.com
m.example.com -> example.com
de.example.com -> }.example.com
example.de -> example.}
example.co.uk -> example.}
public static getLossyUrl ( string $url ) : string | ||
$url | string | |
리턴 | string |
protected function getEngineHostFromUrl($host, $path, $query) { $searchEngines = $this->getDefinitions(); $hostPattern = UrlHelper::getLossyUrl($host); /* * Try to get the best matching 'host' in definitions * 1. check if host + path matches an definition * 2. check if host only matches * 3. check if host pattern + path matches * 4. check if host pattern matches * 5. special handling */ if (array_key_exists($host . $path, $searchEngines)) { $host = $host . $path; } elseif (array_key_exists($host, $searchEngines)) { // no need to change host } elseif (array_key_exists($hostPattern . $path, $searchEngines)) { $host = $hostPattern . $path; } elseif (array_key_exists($hostPattern, $searchEngines)) { $host = $hostPattern; } elseif (!array_key_exists($host, $searchEngines)) { if (!strncmp($query, 'cx=partner-pub-', 15)) { // Google custom search engine $host = 'google.com/cse'; } elseif (!strncmp($path, '/pemonitorhosted/ws/results/', 28)) { // private-label search powered by InfoSpace Metasearch $host = 'wsdsold.infospace.com'; } elseif (strpos($host, '.images.search.yahoo.com') != false) { // Yahoo! Images $host = 'images.search.yahoo.com'; } elseif (strpos($host, '.search.yahoo.com') != false) { // Yahoo! $host = 'search.yahoo.com'; } else { return false; } } return $host; }
/** * @dataProvider getLossyUrls * @group Core */ public function testGetLossyUrl($input, $expected) { $this->assertEquals($expected, UrlHelper::getLossyUrl($input)); }