@samsunikinciel;
Şu betiği deneyebilir misiniz?
<?php
function replace_embedable_youtube_url($string) {
$embed_html = "<iframe width=\"640\" height=\"360\" src=\"http://www.youtube.com/embed/%s\" frameborder=\"0\" allowfullscreen></iframe>";
if(strlen($string) <= 0)
return $string;
$string_parts = explode(" ", $string);
foreach($string_parts as $key => $value) {
$parsed_string_parts = parse_url($string_parts[$key]);
if(array_key_exists("host", $parsed_string_parts)) {
switch($parsed_string_parts["host"]) {
case "youtu.be": {
$string_parts[$key] = sprintf($embed_html, $parsed_string_parts["path"]);
} break;
case ("youtube.com" || "www.youtube.com"): {
$parsed_url_queries = array();
$url_query_parts = explode("&", $parsed_string_parts["query"]);
foreach($url_query_parts as $_key => $_value) {
$query_parts = explode("=", $url_query_parts[$_key]);
$parsed_url_queries[$query_parts[0]] = $query_parts[1];
}
if(array_key_exists("v", $parsed_url_queries))
$string_parts[$key] = sprintf($embed_html, $parsed_url_queries["v"]);
} break;
default: {
#@pass
}
}
}
}
return implode(" ", $string_parts);
}
$string = "saintx http://youtu.be/zxlVvaIEhy0 http://youtube.com/watch?v=zxlVvaIEhy0 http://www.youtube.com/watch?v=zxlVvaIEhy0 saintx";
print_r(
array(
"before" => $string,
"after" => replace_embedable_youtube_url($string)
)
);