我有这样的代码的preg_match和preg_replace函数的YouTube网址
preg_match_all('%(?:youtube\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $asd, $match);
找到像
<a href="http://www.youtube.com/watch?v=">http://www.youtube.com/watch?v=ZiJRPREeQ1Q</a>
<br />
<a href="http://www.youtube.com/watch?v=GaEZgqxPHLs&feature=related">http://www.youtube.com/watch?v=GaEZgqxPHLs&feature=related</a>
这项工作优良网址的YouTube键查找代码ZiJRPREeQ1Q和GaEZgqxPHLs,现在我想更换所有新的代码
想在html线使用
preg_replace
找到整个YouTube网址
<a href="*">*</a>
到一个新的代码,我该怎么办呢?
-------------- --------------增加
后,我通过preg_math_all 从网址查看YouTube的代码,我使用该代码提取码
foreach($match[1] as $youtube){
// $youtube; // this handle the youtube code
$match = ""; // what can i write here relative to $youtube ?
$str .= preg_replace($match, 'new code',$content); // $content handle the whole thread that contain the youtube url <a href=*>*</a>
}
,我唯一需要的是什么,我可以使用,以取代YouTube的代码
请参阅[这里](http://stackoverflow.com/questions/2129443/any-preg-match-to-check-if-a-url-is-a-youtube-vimeo-dailymotion-video-link )和[这里](http://stackoverflow.com/questions/1416425/preg-replace-preg-match-for-href-in-html-link) – sooper 2011-12-29 00:44:23
如果你想“使用”preg_replace,那么你将有了解它是如何工作的。这是完全可行的,但不适合初学者。 (如果你只是想要一些现成的代码,搜索可能会出现一些东西。) – mario 2011-12-29 00:53:13
我更新我的文章,请阅读它 – 2011-12-29 01:24:01