分解 youtube 代码形式的字符串
Exploding youtube code form string
大家好,我遇到了从特定字符串分解 MwLAI_TXowc a 的问题,
我想从下面的youtube代码中爆炸MwLAI_TXowc。
<iframe width="640" height="360" src="https://www.youtube.com/embed/MwLAI_TXowc" frameborder="0" allowfullscreen=""></iframe>
请帮助我如何从 php 中的 youtube 嵌入代码中爆炸 MwLAI_TXowc。
提前致谢
您不必使用 PHP 函数 explode
因为此 PHP 函数 pathinfo
更容易。
<?php
$url = 'https://www.youtube.com/embed/MwLAI_TXowc';
$basename = pathinfo($url)['basename'];
echo '<pre>';
var_dump($basename);
echo '<pre>';
?>
输出
string(11) "MwLAI_TXowc"
或者如果您的 PHP 不支持使用函数直接访问数组
<?php
$url = 'https://www.youtube.com/embed/MwLAI_TXowc';
$pathinfo = pathinfo($url);
$basename = $pathinfo['basename'];
echo '<pre>';
var_dump($basename);
echo '<pre>';
?>
输出
string(11) "MwLAI_TXowc"
对字符串使用 preg_match
$s = '<iframe width="640" height="360" src="https://www.youtube.com/embed/MwLAI_TXowc" frameborder="0" allowfullscreen=""></iframe>';
preg_match('/.*"http.*\/embed\/(.*?)".*/', $s, $matches);
var_dump($matches);
大家好,我遇到了从特定字符串分解 MwLAI_TXowc a 的问题, 我想从下面的youtube代码中爆炸MwLAI_TXowc。
<iframe width="640" height="360" src="https://www.youtube.com/embed/MwLAI_TXowc" frameborder="0" allowfullscreen=""></iframe>
请帮助我如何从 php 中的 youtube 嵌入代码中爆炸 MwLAI_TXowc。 提前致谢
您不必使用 PHP 函数 explode
因为此 PHP 函数 pathinfo
更容易。
<?php
$url = 'https://www.youtube.com/embed/MwLAI_TXowc';
$basename = pathinfo($url)['basename'];
echo '<pre>';
var_dump($basename);
echo '<pre>';
?>
输出
string(11) "MwLAI_TXowc"
或者如果您的 PHP 不支持使用函数直接访问数组
<?php
$url = 'https://www.youtube.com/embed/MwLAI_TXowc';
$pathinfo = pathinfo($url);
$basename = $pathinfo['basename'];
echo '<pre>';
var_dump($basename);
echo '<pre>';
?>
输出
string(11) "MwLAI_TXowc"
对字符串使用 preg_match
$s = '<iframe width="640" height="360" src="https://www.youtube.com/embed/MwLAI_TXowc" frameborder="0" allowfullscreen=""></iframe>';
preg_match('/.*"http.*\/embed\/(.*?)".*/', $s, $matches);
var_dump($matches);