Exemplo n.º 1
0
/**
 * Gets a substring between two other substrings. 
 * 
 * OBS, this returns all the matches,
 * if you are only interested in the first one use get_between instead
 *
 * @author Patrik "Popeen" Johansson <*****@*****.**>
 *
 * @license https://raw.githubusercontent.com/Kakadua/PHP-Snippets/master/LICENSE Unlicense
 *
 * @link https://github.com/Kakadua/PHP-Snippets/
 *
 * @package Kakadua-PHP-Snippets
 *
 * @param String $content The full string you want to check
 * @param String $before The substring before the string you want
 * @param String $after The substring after the string you want
 * @param array $array An internal array, don't pass it in
 *
 * @return array The function returns the read data or an empty array on failure. 
 *
 *	@version 1
 */
function get_between_all($content, $start, $end, $array = array())
{
    $temp = explode($start, $content, 2);
    if (isset($temp[1])) {
        $temp = explode($end, $temp[1], 2);
        $array[] = $temp[0];
        return get_between_all($temp[1], $start, $end, $array);
    } else {
        return $array;
    }
}
function load_show($title, $page)
{
    $raw = file_get_contents("http://www.oppetarkiv.se/etikett/titel/" . urlencode($title) . "/?sida={$page}&sort=tid_stigande&embed=true");
    $episodeRaw = get_between_all($raw, '<article class="svtUnit', 'article>');
    $return = array('last' => !string_contain($raw, 'Visa fler'), 'episodes' => array());
    foreach ($episodeRaw as $episode) {
        $temp = array();
        $temp['title'] = get_between($episode, 'alt="', '"');
        $temp['cover'] = 'http:' . get_between($episode, 'oaImg" src="', '"');
        $temp['year'] = get_between($episode, 'datetime="', '-');
        $temp['aired'] = get_between($episode, 'datetime="', 'T');
        $temp['url'] = 'http://www.oppetarkiv.se' . get_between($episode, ' href="', '"');
        array_push($return['episodes'], $temp);
    }
    return $return;
}