我想将任何 youtube url 转换为 iframe 并将任何网站 url 转换为 php 中的超链接,我有代码但它不能正常工作
这是我的字符串:
Google www.google.com is a best search engine , Google http://www.google.com is a best search engine. http://www.youtube.com/watch?v=BNHR6IQJGZs"
<br/><br/>
我想转换成:
<br/>
"Google <a href="http://www.google.com">www.google.com</a> is a best search engine , Google <a href="http://www.google.com">www.google.com</a> is a best search engine. <div align="center">
<iframe title="YouTube video player" width="480" height="390" src="http://www.youtube.com/embed/BNHR6IQJGZs?autoplay=0" frameborder="0" allowfullscreen></iframe>
</div>"
这是我的代码:
<?php
function ClickableLinksANDyoutubeIframe($text) {
$v = $text;
$v = @eregi_replace("\[yt\]http://www.youtube.com/watch\?v=([^\[]+)\[/yt\]","<iframe title=\"YouTube video player\" class=\"youtube-player\" type=\"text/html\" width=\"400\" height=\"260\" src=\"http://www.youtube.com/embed/\\1\" frameborder=\"0\" allowFullScreen></iframe>",$v);
$v = @eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
'<a href="\\1" target=_blank>\\1</a>', $v);
$v = @eregi_replace('(((f|ht){1}tps://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
'<a href="\\1" target=_blank>\\1</a>', $v);
$v = @eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
'\\1<a href="http://\\2" target=_blank>\\2</a>', $v);
$v = @eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})',
'<a href="mailto:\\1" target=_blank>\\1</a>', $v);
return $v;
}
提前致谢。