Hallo,
Ik heb een PHP functie geschreven.
Om deze uit te voeren duurt het soms een seconde of 3.
Deze functie kijkt op een website naar verschillende foto's en maakt een .xml bestand aan.
Als ik deze functie 1 keer uitvoer werkt het goed.
Alleen zodra ik deze in een foreach() loop stop, dan krijg ik een server error.
Kan iemand me uitleggen wat ik verkeerd doe?
Mijn script
<?php
function testFunction($___url){
$___return = '';
function get_string_between($string, $start, $end){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}
$url = 'http://www.website-met-fotos.nl/'.$___url;
$input = @file_get_contents($url) or die("Could not access file: $url");
$location = get_string_between($input, '<tr><td nowrap="nowrap" colspan="4">', '</td></tr>');
$location = str_replace('<br>', '', $location);
$location = str_replace('<u>', '', $location);
$location = str_replace('</u>', '', $location);
$regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
$tekst = '';
$___return .= '<?xml version="1.0" encoding="UTF-8"?>
<pictures>'.PHP_EOL;
if(preg_match_all("/$regexp/siU", $location, $matches, PREG_SET_ORDER)) {
foreach($matches as $match) {
$parturl = 'http://www.website-met-fotos.nl/'.$___url.'?page='.($match[3]*12-12);
$partinput = @file_get_contents($parturl) or die("Could not access file: $url");
preg_match_all('/<img[^>]+>/i',$partinput, $result);
$img = array();
foreach( $result as $img_tag)
{
foreach($img_tag as $img){
list($width, $height) = getimagesize('http://www.website-met-fotos.nl/'.$___url.'/'.str_replace('; ', '%20', get_string_between($img, '<img src="index.php?image=', '&number=')));
$___return .= ' <foto>'.PHP_EOL;
$___return .= ' <plaatje>'.get_string_between($img, '<img src="index.php?image=', '&number=').'</plaatje>'.PHP_EOL;
$___return .= ' <width>'.$width.'</width>'.PHP_EOL;
$___return .= ' <height>'.$height.'</height>'.PHP_EOL;
$___return .= ' </foto>'.PHP_EOL;
}
}
}
}
$___return .= '</pictures>';
file_put_contents('xml_files/fotos/'.$___url.'.xml', $___return);
mail("[email protected]", "xml test", $___return);
}
$xml = simplexml_load_file('http://www.mijnwebsite.nl/fotoalbums.xml';);
// Aan de hand van deze regel wordt bepaald hoevaak de foreach loop moet worden uitgevoerd.
foreach($xml as $item){
testFunction($item->kort);
}
?>
571 views