hi there
I'm new to php but im trying to replace items on page with a certain id with a image or anything i want. So i have this code on the page
[vimeo 123456]
[vimeo 345675]
my php goes off to vimeo to get the correct image based on the number. but my problem is when i use preg_replace it only every does the same image over each item. So if I have 2 tags on the page I get 2 images but they are the same image.
here is my php code
function vimeo_code($data) {
$replace = "#\[vimeo (.*?)\]#i";
$v_id = preg_match_all($replace, $data, $matches,PREG_PATTERN_ORDER);
function curl_get($url) {
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
$return = curl_exec($curl);
curl_close($curl);
return $return;
}
foreach ($matches[1] as $item){
if (!isset($vimeo_video[$item])){
$vimeo_video[$item]=true;
$api_endpoint = 'http://www.vimeo.com/api/v2/video/'.$item;
$oembed_endpoint = 'http://www.vimeo.com/api/oembed.xml';
$videos = simplexml_load_string(curl_get($api_endpoint.'.xml'));
$video_url = $videos->video->url;
$video_thumbnail_large = $videos->video->thumbnail_large;
$video_title = $videos->video->title;
echo('pp'.$video_thumbnail_large.$video_title);
echo($item);
$data = preg_replace($replace,"<img src=\"$video_thumbnail_large\"",$data);
}
}
echo($data);
}
add_filter('the_content', 'vimeo_code');
it echos the correct images and ids out but not preg_replace
any help would be great
cheers
andy