public function HelperService::parsePlaceUrl in Weather 8
Same name and namespace in other branches
- 2.0.x src/Service/HelperService.php \Drupal\weather\Service\HelperService::parsePlaceUrl()
Parse full link to the place at yr.no site and return useful info.
Parameters
string $url: Full url to the place e.g: https://www.yr.no/place/Ukraine/Kiev/Kyiv/
Return value
array Array with two parsed values: $country - Country of this place (e.g Ukraine or United_States). $link - Internal used link (e.g. Kiev/Kyiv, Maryland/Baltimore)
File
- src/
Service/ HelperService.php, line 200
Class
- HelperService
- HelperService service.
Namespace
Drupal\weather\ServiceCode
public function parsePlaceUrl(string $url) : array {
// Remove "http://www.yr.no/place/" or "https://www.yr.no/place/"
// from the URL.
$url = str_replace('http://www.yr.no/place/', '', $url);
$url = str_replace('https://www.yr.no/place/', '', $url);
// Split by slashes and remove country (first item)
// and "forecast.xml" (last item).
$parts = explode('/', $url);
// Remove country.
$country = array_shift($parts);
// Remove "forecast.xml".
array_pop($parts);
$link = implode('/', $parts);
return [
$country,
$link,
];
}