Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.25 KB | None | 0 0
  1. <?php
  2.  
  3. $url_yt = "https://www.googleapis.com/youtube/v3/channels?part=statistics&id=CHANNELID&key=AIzaSyDLfPQI-rIjdZrd-9hYWOCahgSkZ0J8lgo";
  4.  
  5. $urlParts = parse_url($url_yt);
  6. if($urlParts['query']) {
  7.     parse_str($urlParts['query'], $params);
  8.  
  9.     if($params['id']) {
  10.         $params['id'] = 'hello world'; // $arResult['DISPLAY_PROPERTIES']['QUERY']['VALUE']
  11.         $urlParts['query'] = http_build_query($params);
  12.     }
  13. }
  14.  
  15. echo unparse_url($urlParts);
  16.  
  17. /**
  18. * @link http://php.net/manual/en/function.parse-url.php#106731
  19. */
  20. function unparse_url($parsed_url) {
  21.     $scheme   = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
  22.     $host     = isset($parsed_url['host']) ? $parsed_url['host'] : '';
  23.     $port     = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
  24.     $user     = isset($parsed_url['user']) ? $parsed_url['user'] : '';
  25.     $pass     = isset($parsed_url['pass']) ? ':' . $parsed_url['pass']  : '';
  26.     $pass     = ($user || $pass) ? "$pass@" : '';
  27.     $path     = isset($parsed_url['path']) ? $parsed_url['path'] : '';
  28.     $query    = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
  29.     $fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';
  30.     return "$scheme$user$pass$host$port$path$query$fragment";
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement