'; $player = str_replace("{w}", $w, $player); $player = str_replace("{h}", $h, $player); foreach($matches as $m){ $text = str_replace($m, str_replace("{id}", YoutubeLinkParser::getVideoId($m), $player), $text); } return $text; } } $text = "afdasd fasdfa sdf http://www.youtube.com/watch?v=PgUOs-LV0EI&feature=related asdfasd afasdf http://www.youtube.com/watch?v=sHUNxn38VAs asfasdf asdfads f adsfa http://br.youtube.com/watch?v=sHUNxn38VAs&opa=opa"; // all the ocurrencies of a youtube link $ocurrencies = YoutubeLinkParser::getOcurrencies($text); print_r($returns); // returns the video id from a youtube URL echo YoutubeLinkParser::getVideoId("http://www.youtube.com/watch?v=PgUOs-LV0EI&feature=related"); // parses a long text that contains youtube links and return the youtube player instead of the text link echo YoutubeLinkParser::addPlayer($text, 400, 500); ?>