function getArticleIntro($article) { if ($article) { $maxChar = 250; #Could for some reason not set this through param in function call $apiurl = 'https://sv.wikipedia.org/w/api.php?'; $query = array('action' => 'query', 'prop' => 'extracts', 'format' => 'php', 'exchars' => $maxChar, 'exintro' => '', 'explaintext' => '', 'titles' => $article); $queryUrl = $apiurl . http_build_query($query, $enc_type = 'PHP_QUERY_RFC3986'); #$queryUrl = $apiurl.'action=query&prop=extracts&format=php&exchars='.$maxChar.'&exintro=&titles='.rawurlencode($article); $page = ApiBase::get_curl_data($queryUrl); if (is_null($page)) { return null; } else { $response = unserialize($page); $pageId = key($response['query']['pages']); if ($pageId != -1) { $intro = $response['query']['pages'][$pageId]['extract']; #remove any coordinates templates $pos = strpos($intro, "Koordinater:"); if ($pos !== false) { $newintro = trim(substr($intro, 0, $pos)); $endpos = strpos($intro, "\n", $pos + 1); if ($endpos !== false) { $newintro .= ' ' . trim(substr($intro, $endpos)); } $intro = $newintro; } return $intro; } } } }