获取帖子内特定URL的ID,并将其保存在变量中 [英] Get id of a particular URL inside the post and save it in a variable

查看:73
本文介绍了获取帖子内特定URL的ID,并将其保存在变量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的帖子里面的视频具有以下代码:

Inside my posts videos have code below:

[videojs mp4="http://www.example.com/video-play.mp4?contentId=7c6255ca14e901d2" poster="https://2.bp.example.com/-lSTjYuDBiAQ/VvST8Z7z2OI/AAAAAAAAGPY/c8yAE675bLEMYI-OMwtauCiXeu1yZPZaw/s1600/fundososvideos.jpg" preload="none" controls="controls" width="100%" height="400"]

我需要从此URL http://www.example.com/video-play.mp4?contentId=7c6255ca14e901d2获取ID 7c6255ca14e901d2,并将其保存在要在页面上使用的变量中.

I need to get the ID 7c6255ca14e901d2 from this url http://www.example.com/video-play.mp4?contentId=7c6255ca14e901d2 and save in a variable to be used on a page.

有人可以解释我该怎么做吗?

Could someone explain me how to do?

推荐答案

假设您将整个 [videojs mp4 ="uri" ---...] 用作字符串.现在,您要对其进行处理,并将其分配给几个不同的变量以备将来使用.

Its an assumption that you get the whole [videojs mp4="uri" ---...] as string. Now, you wants to process it and assign it to several different variables for future use.

$video_string = '[videojs mp4="http://www.blogger.com/video-play.mp4?contentId=7c6255ca14e901d2" poster="https://2.bp.blogspot.com/-lSTjYuDBiAQ/VvST8Z7z2OI/AAAAAAAAGPY/c8yAE675bLEMYI-OMwtauCiXeu1yZPZaw/s1600/fundososvideos.jpg" preload="none" controls="controls" width="100%" height="400"]';
if (preg_match('/mp4="(.*)"\sposter/', $video_string, $matches1)) {

    $url = $matches1[1];
    $id = explode('=',parse_url($url)['query'])[1];
    echo 'From Video string I get Id= '.$id . ' & url = '.$url;
}

这篇关于获取帖子内特定URL的ID,并将其保存在变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆