maxworkingwell

get film rating from kinopoisk and imdb

Dec 19th, 2021 (edited)
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.55 KB | None | 0 0
  1. // get film rating from  kinopoisk and imdb - example [get_rating film="6750" site="kp"]
  2. add_shortcode('get_rating', 'get_rating_func');
  3. function get_rating_func( $atts ) {
  4.  $film = $atts['film'];
  5.  $site = $atts['site'];
  6.  $rating = [];
  7.  $xml   = simplexml_load_file( 'https://rating.kinopoisk.ru/' . $film . '.xml' );
  8.  $names = ['kp_rating', 'imdb_rating'];
  9.  foreach ( $names as $name ) {
  10.  $new_name            = str_replace( '_rating', '', $name );
  11.  $rating[ $new_name ] = dom_import_simplexml( $xml->$name )->nodeValue;
  12.  }
  13.  return $rating[$site];
  14. }
Add Comment
Please, Sign In to add comment