At the moment I have this to check whether the $content is containing youtube link and if so then run the function youtubeFetchDataCallback():
if (preg_match("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=[0-9]/)[^&
]+|(?<=v=)[^&
]+#", $content, $matches)) {
echo '<script type="text/javascript">';
foreach(array_unique($matches) as $m) {
echo "
$.getJSON (
'http://gdata.youtube.com/feeds/api/videos/$m?v=2&alt=json-in-script&callback=?',
function(data) {
youtubeFetchDataCallback(data, $id, '".$m."');
}
);
";
}
echo '</script>';
}
This do work just fine although I wish to modify this so if there is a youtube link, remove it from the $content and run youtubeFetchDataCallback.
So by remove, maybe replace the youtubelink to '' (empty).
How can I do this? Thank you
UPDATE: Tried this so far:
if (preg_match("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=[0-9]/)[^&
]+|(?<=v=)[^&
]+#", $content, $matches)) {
echo '<script type="text/javascript">';
foreach(array_unique($matches) as $m) {
echo "
$.getJSON (
'http://gdata.youtube.com/feeds/api/videos/$m?v=2&alt=json-in-script&callback=?',
function(data) {
youtubeFetchDataCallback(data, $id, '".$m."');
}
);
";
}
echo '</script>';
}
$content = preg_replace("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=[0-9]/)[^&
]+|(?<=v=)[^&
]+#", '', $content);
echo $content;
?>
The videolink still is in the $content