fork(1) download
  1. <?php
  2.  
  3. function getYouTubeXMLUrl( $url) {
  4.  
  5. $xml_youtube_url_base = 'https://w...content-available-to-author-only...e.com/feeds/videos.xml';
  6. $preg_entities = [
  7. 'channel_id' => '\/channel\/([^\/?]+)', //match YouTube channel ID from url
  8. 'user' => '\/user\/([^\/?]+)', //match YouTube user from url
  9. ];
  10.  
  11. foreach ( $preg_entities as $key => $preg_entity ) {
  12. if ( preg_match( '/' . $preg_entity . '/', $url, $matches ) ) {
  13. if ( isset( $matches[1] ) ) {
  14. return [
  15. 'rss' => $xml_youtube_url_base . '?' . $key . '=' . $matches[1],
  16. 'id' => $matches[1],
  17. 'type' => $key,
  18. ];
  19. }
  20. }
  21. }
  22. }
  23.  
  24. // works
  25. $url = 'https://y...content-available-to-author-only...e.com/channel/UCBLAoqCQyz6a0OvwXWzKZag/asdasd';
  26.  
  27. $channel = getYouTubeXMLUrl($url);
  28. print_r($channel);
  29.  
  30. // doesn't work
  31. $url = 'https://y...content-available-to-author-only...e.com/channel/UCBLAoqCQyz6a0OvwXWzKZag?hello=worlddddddd';
  32. $url = 'https://y...content-available-to-author-only...e.com/channel/UCBLAoqCQyz6a0OvwXWzKZag/hello';
  33.  
  34.  
Success #stdin #stdout 0.01s 24600KB
stdin
Standard input is empty
stdout
Array
(
    [rss] => https://w...content-available-to-author-only...e.com/feeds/videos.xml?channel_id=UCBLAoqCQyz6a0OvwXWzKZag
    [id] => UCBLAoqCQyz6a0OvwXWzKZag
    [type] => channel_id
)