<?php PHPOEmbed::addProvider(new PHPOEmbedProvider('http://www.youtube.com/oembed?url=:url&format=json', array('~youtube\\.com/watch.+v=[\\w-]+&?~', '~youtu.be\\/[\\w-]+~'), 'youtube')); PHPOEmbed::addProvider(new PHPOEmbedProvider('http://www.flickr.com/services/oembed?url=:url&format=json', '~flickr\\.com/photos/[-.\\w@]+/\\d+/?~', 'fliker')); PHPOEmbed::addProvider(new PHPOEmbedProvider('http://www.vimeo.com/api/oembed.json?url=:url', '~vimeo\\.com/.+~', 'vimeo')); PHPOEmbed::addProvider(new PHPOEmbedProvider('http://www.hulu.com/api/oembed.json?url=:url', '~hulu\\.com/watch/.+~', 'hulu')); PHPOEmbed::addProvider(new PHPOEmbedProvider('http://www.polleverywhere.com/services/oembed?url=:url&format=json', array('~polleverywhere\\.com/polls/.+~', '~polleverywhere\\.com/multiple_choice_polls/.+~', '~polleverywhere\\.com/free_text_polls/.+~'), 'polle'));
/** * This is the constractor function. It checks the all the requirements * before creating the object, including php version checking. * * ### Warning * * @param int $timeOut provide the timeout in seconds. * (Leave it or set it to null if you do not know what you are doing, risky.) * @param string $userAgent provide a valid user agent. * (Same here, leave it or set it to null if you do not know what you are doing, risky.) */ public function __construct($timeOut = null, $userAgent = null) { if ($timeOut >= 0) { self::$timeout = $timeOut; } if (is_string($userAgent)) { self::$userAgent = $userAgent; } //now check the php version. if (version_compare(PHP_VERSION, '5.3', '<')) { trigger_error("PHP version 5.3+ require."); } if (!function_exists('curl_init')) { trigger_error("curl extention require to run."); } }
<?php include '../src/oEmbed.php'; if (isset($_REQUEST['url'])) { $OE = new PHPOEmbed(null, null); $data = json_decode($OE->parse($_REQUEST['url']), true); print_r($data); //$data2 = json_decode($OE->parse('youtube.com'), true); // function cool( $data ){ // if ( isset($data['title']) ){ // echo '<h1>' . $data['title'] . '</h1>'; // } // // if ( isset($data['url']) ){ // echo '<p><a href="' . $data['url'] . '" terget="_blank">' . $data['url'] . '</a> ' . ( isset($data['author_name']) ? ' | ' . $data['author_name'] : '' ) . '</p>'; // } // // if ( isset($data['description']) ){ // echo '<p>' . $data['description'] . '</p>'; // } // // foreach ( $data['photos'] as $img ){ // echo '<img src="' . $img . '">'; // } // } // // cool($data); } else { echo 'use test/?url=example.com to test'; }