простой способ передачи массива из php в js

$(document).ready(function($){
		
			$.ajax({
				url:'/fest/get_imgs.php',
				success:function(data){
					imgs=data.split(' ');
					function getRandomInt(min, max){
						return Math.floor(Math.random()*(max-min+1))+min;
					}
					var fn=function(){
						url=imgs[getRandomInt(0,imgs.length-1)];
						$('#pictures_block').html('<a href="'+url+'" class="fancybox"><img src="'+url+'" /></a>');
						setTimeout(arguments.callee, 5000);
					}
					setTimeout(fn, 5000);
					url_first=imgs[getRandomInt(0,imgs.length-1)];
					$('#pictures_block').html('<a href="'+url_first+'" class="fancybox"><img src="'+url_first+'" /></a>');
				},
				cache: false
			});
			
		});

get_img.php:

function file_get_contents_curl($href){
	$ch=curl_init();
	curl_setopt($ch, CURLOPT_HEADER, 0);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_URL, $href);
	$data=curl_exec($ch);
	curl_close($ch);
	return $data;
}
$domain='http://domain.ru';
$href=$domain.'/page/pict/';
$data=file_get_contents_curl($href);
if($data!=false){
	preg_match_all("/<div class=\"topic\">(.*?)\t\t<\/div> <!-- \/content -->/is",$data,$arr1);
	preg_match_all('/src="(.*?)"/is',$arr1[1][0],$arr2);
	$count=count($arr2[1]);
	if($count>0){
		foreach($arr2[1] as $key=>$img_href){
			echo str_replace($domain, '', $img_href);
			if($key<$count-1)
				echo ' ';
		}
	}
}



Подписаться на рассылку новостей сайта через FeedBurner:

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *