There is a code that displays a list of video titles on the YouTube channel:

<?php $content=file_get_contents('https://www.youtube.com/user/Fletcher2008/videos'); $content=preg_replace('/[\s]+/',' ',$content); $content=preg_replace('/"/','',$content); $content=preg_replace('/href=\/watch\?v=/',"\n",$content); $content=preg_replace('/<(span|img)[^>]*>/','',$content); $content=preg_replace('/<\/(span|img)>/','',$content); $content=preg_replace('/[\s]*class=[^>^\n]*>/','>',$content); $content=preg_replace('/>[\s]*/','>',$content); $content=preg_replace('/[\s]*</','<',$content); $content=preg_replace('/<button.*/','',$content); $content=preg_replace('/><\/a>/','\',\'',$content); $content=preg_replace('/<\/a>.*/','',$content); $lines = preg_split('/\n/', $content); $count=0; foreach($lines as $line){ if($count==0) { $count=1; } else if($count==1) { $sql.="('".$line."',"; $count=2; } else if($count==2) { $line=preg_replace('/^[^>]*>/','',$line); $sql.="'".$line."'),\n"; $count=1; echo $line."<br>"; } } ?> 

Tell me how to display more links to these videos?

    1 answer 1

    Using your approach you can do this:

     <?php $content=file_get_contents('https://www.youtube.com/user/Fletcher2008/videos'); if (preg_match_all('%<h3 class="yt-lockup-title"><a[^>]*href="([^"]+)"[^>]*>([^<]+)%iu', $content, $matches)) { header('Content-type: text/html; charset=utf-8'); $count = count($matches[0]); for ($i = 0; $i < $count; $i++) { echo htmlspecialchars($matches[1][$i], ENT_QUOTES, 'UTF-8'); echo ' --- '; echo htmlspecialchars($matches[2][$i], ENT_QUOTES, 'UTF-8'); echo "<br>\n"; } } 

    PS But youtube have api for this.

    • Thanks, but if there are several links, for example: $ content = file_get_contents (' youtube.com/user/Fletcher2008/videos' ); $ content = file_get_contents (' youtube.com/user/gsstudiodota/videos' ); how to make sure they parse in turn - lxxnutsxxl
    • Links YouTube pages put into an array and loop through them, and inside the loop, parse the current one. - Visman
    • Can you give me an example? - lxxnutsxxl
    • If you do not know how to write a cycle and insert this code into the cycle, then you should contact the freelance market with this task. - Visman
    • Thank you very much, I figured it out! - lxxnutsxxl