重写 Youtube URL [英] Rewrite Youtube URL
本文介绍了重写 Youtube URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在数据库中存储了一些 YouTube 网址,需要重写.
I have some YouTube URLs stored in a database that I need to rewrite.
它们以这种格式存储:
$http://youtu.be/IkZuQ-aTIs0
我需要重新编写它们,使其看起来像这样:
I need to have them re-written to look like this:
$http://youtube.com/v/IkZuQ-aTIs0
这些值存储为变量 $VideoType
These values are stored as a variable $VideoType
我这样调用变量:
$<?php if ($video['VideoType']){
$echo "<a rel=\"shadowbox;width=700;height=400;player=swf\" href=\"" . $video['VideoType'] . "\">View Video</a>";
$}?>
我该如何重写它们?
感谢您的帮助.
推荐答案
您想使用 preg_replace
功能:
类似于:
$oldurl = 'youtu.be/blah';
$pattern = '/youtu.be/';
$replacement = 'youtube.com/v';
$newurl = preg_replace($pattern, $replacement, $string);
这篇关于重写 Youtube URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文