<?php
if(isset($_GET["url"])){
$handle = curl_init();
$url = "https://www.memrise.com/course/126065/a1-german-2/1/";
$url = "https://www.memrise.com/course/427841/german-studio-d-a1-vocabulary/3/";
$url = $_GET["url"];
$urlParts = explode("/",$url);
$cachedAddress = "cached/". $urlParts[sizeof($urlParts)-3].$urlParts[sizeof($urlParts)-2].".html";
// $pattern = `#<div class="text">(.*?)<\/div>#`;
// $pattern = /text">((.|\n)*?)</;
// Set the url
curl_setopt($handle, CURLOPT_URL, $url);
// Set the result output to be a string.
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
echo $output = curl_exec($handle);
curl_close($handle);
file_put_contents($cachedAddress,$output);
echo "written";
// echo $output;
// preg_match_all($pattern, $output, $matches);
// print_r($matches);
}