function parseYoutubeUrls($text, $width = -1, $height = -1) { // defaults if($width == -1) { $width = 425; } if($height == -1) { $height = round((344/425) * $width); } // get all urls in text $regexp = "/]*)[\"\']?[^>]*>(.*)<\/a>/i"; if(preg_match_all($regexp, $text, $matches, PREG_SET_ORDER)) { // check each url foreach($matches as $match) { // replace all youtube urls with embedded flash player if(preg_match_all("/www.youtube.com/",$match[1],$hit)) { $parsedUrl = parse_url($match[1]); parse_str($parsedUrl["query"], $query); $videoId = ($query['v']); $replace = '

'; $text = str_replace($match[0],$replace, $text); } } } return $text; }