Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何替换字符串,让youtube以新的共享代码编写?_Php_Youtube - Fatal编程技术网

Php 如何替换字符串,让youtube以新的共享代码编写?

Php 如何替换字符串,让youtube以新的共享代码编写?,php,youtube,Php,Youtube,不是一个程序员,只是一个论坛管理员,所以任何直接的答案都会非常感谢,因为我知道这是一个简单的答案 我有一个过时的论坛模版来嵌入youtube视频。Youtube更改了他们的共享链接,我不知道如何更新,这样人们就可以发布www.Youtube.com/watch?=v(location)的旧格式和youtu.be/(location)的新格式 $passiveId[]=数组( 'string'=>'#'。$urlrx[0]。(?:[a-zA-Z]{1,4}\)?youtube.com/(?:wat

不是一个程序员,只是一个论坛管理员,所以任何直接的答案都会非常感谢,因为我知道这是一个简单的答案

我有一个过时的论坛模版来嵌入youtube视频。Youtube更改了他们的共享链接,我不知道如何更新,这样人们就可以发布www.Youtube.com/watch?=v(location)的旧格式和youtu.be/(location)的新格式

$passiveId[]=数组(
'string'=>'#'。$urlrx[0]。(?:[a-zA-Z]{1,4}\)?youtube.com/(?:watch)?\?v=(.11}?)。$urlrx[1]。#,
'replacement'=>'$PASSIVEURL=$matches[1];$PASSIVETITLE=$matches[3];$PASSIVEEMBED=\'\';return'.$customstring.';',
“id”=>1
);
$passiveId[]=数组(
'字符串'=>'\[youtube\]([^\[\]]+)\[/youtube\]\\',
“替换”=>“返回\'\';”,
“id”=>1
);

虽然我不是正则表达式方面的专家,但这可能会奏效:

$passiveVid[] = array(
    'string' => '#' . $urlrx[0] . '(?:[a-zA-Z]{1,4}\.)?youtube.com/(?:watch)?\?v=(.{11}?)' . $urlrx[1] . '#',
    'replacement' => '$PASSIVEURL = $matches[1]; $PASSIVETITLE = $matches[3]; $PASSIVEEMBED = \'<object width="712" height="400"><param name="movie" value="http://www.youtube.com/v/\'.$matches[2].\'"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/\'.$matches[2].\'" type="application/x-shockwave-flash" wmode="transparent" width="712" height="400"></embed></object>\'; return "' . $customstring . '";',
    'id' => 1
);
$passiveVid[] = array(
    'string' => '#\[youtube\]([^\[\]]+)\[/youtube\]#',
    'replacement' => 'return \'<object width="712" height="400"><param name="movie" value="http://www.youtube.com/v/\'.$matches[1].\'"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/\'.$matches[1].\'" type="application/x-shockwave-flash" wmode="transparent" width="712" height="400"></embed></object>\';',
    'id' => 1
);
$passiveVid[] = array(
    'string' => '#' . $urlrx[0] . '(?:[a-zA-Z]{1,4}\.)?youtu.be/(.{11}?)' . $urlrx[1] . '#',
    'replacement' => '$PASSIVEURL = $matches[1]; $PASSIVETITLE = $matches[3]; $PASSIVEEMBED = \'<object width="712" height="400"><param name="movie" value="http://www.youtube.com/v/\'.$matches[2].\'"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/\'.$matches[2].\'" type="application/x-shockwave-flash" wmode="transparent" width="712" height="400"></embed></object>\'; return "' . $customstring . '";',
    'id' => 1
);
$passiveVid[] = array(
    'string' => '#\[youtu\]([^\[\]]+)\[/youtu\]#',
    'replacement' => 'return \'<object width="712" height="400"><param name="movie" value="http://www.youtube.com/v/\'.$matches[1].\'"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/\'.$matches[1].\'" type="application/x-shockwave-flash" wmode="transparent" width="712" height="400"></embed></object>\';',
    'id' => 1
);

以上是您的其他代码,这比使用正则表达式进行f-ing要简单一些:)。

谢谢!长的有效,短的无效。作为第一行,短的一个应该放在哪里?在另外两个新阵列的上面。但这不是一个复制/粘贴的答案,你必须摆弄它才能工作。但只要短的一个有效,我很乐意帮助!
$passiveVid[] = array(
    'string' => '#' . $urlrx[0] . '(?:[a-zA-Z]{1,4}\.)?youtube.com/(?:watch)?\?v=(.{11}?)' . $urlrx[1] . '#',
    'replacement' => '$PASSIVEURL = $matches[1]; $PASSIVETITLE = $matches[3]; $PASSIVEEMBED = \'<object width="712" height="400"><param name="movie" value="http://www.youtube.com/v/\'.$matches[2].\'"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/\'.$matches[2].\'" type="application/x-shockwave-flash" wmode="transparent" width="712" height="400"></embed></object>\'; return "' . $customstring . '";',
    'id' => 1
);
$passiveVid[] = array(
    'string' => '#\[youtube\]([^\[\]]+)\[/youtube\]#',
    'replacement' => 'return \'<object width="712" height="400"><param name="movie" value="http://www.youtube.com/v/\'.$matches[1].\'"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/\'.$matches[1].\'" type="application/x-shockwave-flash" wmode="transparent" width="712" height="400"></embed></object>\';',
    'id' => 1
);
$passiveVid[] = array(
    'string' => '#' . $urlrx[0] . '(?:[a-zA-Z]{1,4}\.)?youtu.be/(.{11}?)' . $urlrx[1] . '#',
    'replacement' => '$PASSIVEURL = $matches[1]; $PASSIVETITLE = $matches[3]; $PASSIVEEMBED = \'<object width="712" height="400"><param name="movie" value="http://www.youtube.com/v/\'.$matches[2].\'"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/\'.$matches[2].\'" type="application/x-shockwave-flash" wmode="transparent" width="712" height="400"></embed></object>\'; return "' . $customstring . '";',
    'id' => 1
);
$passiveVid[] = array(
    'string' => '#\[youtu\]([^\[\]]+)\[/youtu\]#',
    'replacement' => 'return \'<object width="712" height="400"><param name="movie" value="http://www.youtube.com/v/\'.$matches[1].\'"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/\'.$matches[1].\'" type="application/x-shockwave-flash" wmode="transparent" width="712" height="400"></embed></object>\';',
    'id' => 1
);
$newString = str_replace('youtu.be/', 'youtube.com/watch?v=', $originalString);