/siU", $index, $matches); // Assemble the urls $list = array_map(function ($href) use ($serviceUrl) { // Replace the url encoded single slash with a real one. $href = str_replace(''', "'", $href); // Convert 'US/CA' into 'US_CA.json'. $filename = str_replace('/', '_', $href) . '.json'; $url = $serviceUrl . '/data/' . $href; // aria2 expects the out= parameter to be in the next row, // indented by two spaces. $url .= "\n out=$filename"; return $url; }, $matches[1]); return implode("\n", $list); }