Get id of a particular URL inside the post and save it in a variable

后端 未结 2 439
走了就别回头了
走了就别回头了 2020-12-22 13:36

Inside my posts videos have code below:

[videojs mp4=\"http://www.example.com/video-play.mp4?contentId=7c6255ca14e901d2\" poster=\"https://2.bp.example.com/-         


        
2条回答
  •  醉酒成梦
    2020-12-22 13:55

    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;
    }
    

提交回复
热议问题