php - How to find in html (from url) tag attributte -


   <?php       $html = file_get_contents('https://vine.co/v/h5pzjxyihra/card');     //$videosrc = ?;     ?> 

with function file_get_contents()

i html content of url.

i need in html find tag <source src="https://v.cdn.vine.co/r/videos/xxxxx.mp4 " type="video/mp4">

how source attribute src?

theres few ways this.

1. php dom - http://us1.php.net/dom

this doo-hickey make xml/xhtml object given source code supply. it's kind of tree structure can traverse through.

2. php xml - http://php.net/manual/en/book.xml.php

just #1 older xml parser.

3. string literal searching - http://php.net/manual/en/function.strpos.php

this oldey goody. use strpos() find source tag start, again find src tag , grab string. require tags perfect , doesn't leave lot of flexibility.

$source = strpos($html, '<source '); if($source!==false) {   $src_loc = strpos($html, 'src="', $source);   if($src_loc!==false) {     $end_quote = strpos($html, '"', $src_loc + 5);     if($end_quote!==false) {       $final_src = substr($html, $src_loc+5, $end_quote-($src_loc+5)); //tada!     }   } } 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -