Home > Enterprise >  How can I get src of video from HTML
How can I get src of video from HTML

Time:12-14

on example.com is <video> like:

<video controls="" preload="false" src="http://example.com/video.mp4"></video>

and I would like to get content of src="" which is inside of that <video> tag

(example.com is not my website, I need to use PHP to get to the HTML code and get the src from the video tag)

thank you!

CodePudding user response:

Quick and dirty way

<?php
preg_match_all('#<video .*?src="(.*?)"#', file_get_contents('https://example.com'), $results);

print_r($results[1]);

A better way is to use web scraping/crawling tools like FriendsOfPHP/Goutte

CodePudding user response:

If you want to get any value in php you have to do an Ajax call and send the data:

   $('#element').click(function({
             var src = $(this).attr('src');
             $.ajax({
                url:'/someFile.php/ajax/',
                type:'post',
                dataType:'json',
                data:{
                    src:src;
                },
                success:function(data){
                   console.log('src sended');
                }
             });
         });

Check out this: JQuery Ajax

  • Related