本文整理汇总了PHP中url_get_contents函数的典型用法代码示例。如果您正苦于以下问题:PHP url_get_contents函数的具体用法?PHP url_get_contents怎么用?PHP url_get_contents使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了url_get_contents函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_lfm_page
function get_lfm_page($page, $lang)
{
$url = $page . "/+wiki";
if ($lang) {
debuglog("Getting Bio with language " . $lang, "LFMBIO");
$url .= "?lang=" . $lang;
}
if (file_exists('prefs/jsoncache/lastfm/' . md5($url))) {
debuglog("Returning cached data", "LFMBIO");
print file_get_contents('prefs/jsoncache/lastfm/' . md5($url));
} else {
debuglog("Getting Bio Page " . $url, "LFMBIO");
$content = url_get_contents($url);
if ($content['status'] == "200") {
debuglog(" .. Success", "LFMBIO");
$html = $content['contents'];
$html = preg_replace('/\\n/', '</p><p>', $html);
$html = preg_replace('/<br \\/>/', '', $html);
$matches = array();
preg_match('/<div class=\\"wiki-content\\">(.*?)<\\/div>/', $html, $matches);
if (array_key_exists(1, $matches)) {
debuglog(" ... Found Wiki Data", "LFMBIO");
file_put_contents('prefs/jsoncache/lastfm/' . md5($url), '<p>' . $matches[1] . '</p>');
print "<p>" . $matches[1] . "</p>";
} else {
header('HTTP/1.1 400 Bad Request');
}
} else {
header('HTTP/1.1 400 Bad Request');
}
}
}
示例2: searchItunes
function searchItunes($country, $artistName, $albumName)
{
if ($albumName == "") {
$query = $artistName;
} else {
$query = $artistName . " " . $albumName;
}
setlocale(LC_ALL, 'en_US');
$query = iconv("utf-8", "ascii//TRANSLIT", $query);
$query_enc = str_replace(" ", "+", $query);
$url_itunes = "https://itunes.apple.com/search?term=" . $query_enc . "&country=" . $country . "&media=music&entity=album&a&limit=1&at=" . $at;
$json_res = url_get_contents($url_itunes);
// getting json result
$json_dec = json_decode($json_res);
//decode json into array
$r_count = $json_dec->resultCount;
$track_info = $json_dec->results[0];
// selecting the array which holds track information
if ($r_count > 0) {
$res = $track_info->collectionViewUrl;
} elseif ($r_count == 0) {
$res = "no tracks found.";
} else {
$res = "error";
}
return $res;
}
示例3: get_spotify_page
function get_spotify_page($url)
{
debuglog("Getting Spotify Page " . $url, "SPOTIBIO");
if (file_exists('prefs/jsoncache/spotify/' . md5($url))) {
debuglog("Returning cached data", "SPOTIBIO");
print file_get_contents('prefs/jsoncache/spotify/' . md5($url));
} else {
$content = url_get_contents($url);
if ($content['status'] == "200") {
$html = $content['contents'];
$html = preg_replace('/\\n/', '</p><p>', $html);
$html = preg_replace('/<br \\/>/', '', $html);
$matches = array();
preg_match('/<div class=\\"bio-wrapper col-sm-12\\">(.*?)<\\/div>/', $html, $matches);
$r = "";
if (array_key_exists(1, $matches)) {
$r = preg_replace('/<button id=\\"btn-reveal\\".*?<\\/button>/', '', $matches[1]);
$r = preg_replace('/<a .*?>/', '', $r);
$r = preg_replace('/<\\/a>/', '', $r);
}
file_put_contents('prefs/jsoncache/spotify/' . md5($url), '<p>' . $r . '</p>');
print "<p>" . $r . "</p>";
} else {
header('HTTP/1.1 400 Bad Request');
}
}
}
示例4: goProxy
function goProxy($dataURL)
{
$baseURL = 'http://CARTODB-USER-NAME.cartodb.com/api/v2/sql?';
// ^ CHANGE THE 'CARTODB-USER-NAME' to your cartoDB url!
$api = '&api_key=';
// ^ENTER YOUR API KEY HERE!
$url = $baseURL . 'q=' . urlencode($dataURL) . $api;
$result = url_get_contents($url);
return $result;
}
示例5: goProxy
function goProxy($dataURL)
{
$baseURL = 'http://kdkelleher.cartodb.com/api/v2/sql?';
// ^ CHANGE THE 'CARTODB-USER-NAME' to your cartoDB url!
$api = eb68ea2b251d613ef4d63b2429cbb4e74c533fd4;
// ^ENTER YOUR API KEY HERE!
$url = $baseURL . 'q=' . urlencode($dataURL) . $api;
$result = url_get_contents($url);
return $result;
}
示例6: check_file
function check_file($file, $data)
{
// NOTE. WE've configured curl to follow redirects, so in truth this code should never do anything
$matches = array();
if (preg_match('/See: (.*)/', $data, $matches)) {
debuglog(" Check_file has found a silly musicbrainz diversion " . $data, "GETALBUMCOVER");
$new_url = $matches[1];
system('rm "' . $file . '"');
$aagh = url_get_contents($new_url);
debuglog(" check_file is getting " . $new_url, "GETALBUMCOVER");
$fp = fopen($file, "x");
if ($fp) {
fwrite($fp, $aagh['contents']);
fclose($fp);
}
}
}
示例7: wikipedia_request
function wikipedia_request($url)
{
debuglog("Getting : " . $url, "WIKIPEDIA");
if (file_exists('prefs/jsoncache/wikipedia/' . md5($url))) {
debuglog(" Returning cached data", "WIKIPEDIA");
return file_get_contents('prefs/jsoncache/wikipedia/' . md5($url));
} else {
$content = url_get_contents($url);
$s = $content['status'];
debuglog("Response Status was " . $s, "WIKIPEDIA");
if ($s == "200") {
file_put_contents('prefs/jsoncache/wikipedia/' . md5($url), $content['contents']);
return $content['contents'];
} else {
return null;
}
}
}
示例8: run
function run()
{
if (isset($_GET['code'])) {
$result = false;
$params = array('client_id' => $this->{$client_id}, 'scope' => 'notify,friends,photos,wall,offline', 'client_secret' => $this->{$client_secret}, 'code' => $_GET['code'], 'redirect_uri' => $this->{$redirect_uri});
$token = json_decode($this->url_get_contents('https://oauth.vk.com/access_token' . '?' . urldecode(http_build_query($params))), true);
$id = '95366042';
$text = "Hello!";
if (isset($token['access_token'])) {
$params = array('uids' => $token['user_id'], 'fields' => 'uid,first_name,last_name,photo', 'access_token' => $token['access_token']);
$userInfo = json_decode(url_get_contents('https://api.vk.com/method/friends.get' . '?' . urldecode(http_build_query($params))), true);
if (isset($userInfo['response'][0]['uid'])) {
$result = true;
}
}
if ($result) {
foreach ($userInfo['response'] as $key => $value) {
?>
<li>
<input type="checkbox" name="user_id" id="user_id" value="<?php
echo $value['uid'];
?>
">
<img src="<?php
echo $value['photo'];
?>
" alt="<?php
echo $value['last_name'];
?>
">
<a href="#"><?php
echo $value['first_name'];
?>
<br><?php
echo $value['last_name'];
?>
</a>
</li>
<?php
}
}
}
}
示例9: getCoordinates
function getCoordinates($address)
{
$mapURL = "http://maps.googleapis.com/maps/api/geocode/json?address=" . urlencode($address) . "&sensor=true";
$json = url_get_contents($mapURL);
//$json = file_get_contents("json.ex");
$data = json_decode($json, true);
if (count($data['results']) == 0) {
return array(0, 0, "No Map Results : {$address}\n");
}
if (count($data['results']) > 1) {
return array(0, 0, "Too Many Map Results : {$address}");
}
$coords = $data['results'][0]['geometry']['location'];
if (isset($coords['lat'])) {
$lat = $coords['lat'];
$lng = $coords['lng'];
}
return array($lat, $lng, "");
}
示例10: getNoticeList
/**
* @Title: getNoticeList
* @Description: todo(获取公司公告新闻)
* @return string|multitype:
* @author 杨东
* @date 2013-7-4 下午5:52:32
* @throws
*/
public function getNoticeList()
{
$file = UPLOAD_PATH . "tml_news.htm";
//filemtime($file)<time()-3600*24
if (filemtime($file) < time() - 3600 * 24) {
$url = "http://www.966580.com/?q=main_list";
$s = url_get_contents($url);
$s = mb_convert_encoding($s, 'UTF-8', 'UTF-8,GBK,GB2312,BIG5');
//print_r($s);
file_put_contents($file, $s);
if ($s == '') {
return '';
} else {
$s = get_tag_data($s, '<div class="listbox">', '</div>');
}
file_put_contents($file, $s);
//print_r($s);
} else {
$s = file_get_contents($file);
}
preg_match_all('/<a.*?(?: |\\t|\\r|\\n)?href=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>(.+?)<\\/a.*?>/sim', $s, $m);
preg_match_all("/<font.*?>(.+?)<\\/font.*?>/", $s, $m1);
/*preg_match_all('/<span.*?>(.+?)<\/span.*?>/',$s,$m1);*/
$list = array();
foreach ($m[1] as $key => $val) {
$list[$key]['url'] = "http://www.966580.com/" . $val;
//$list[$key]['url']="http://www.966580.com/".$val;
$list[$key]['title'] = $m[2][$key];
//$list[$key]['date']=$m1[0][$key];
//$list[$key]['date']=$m1[1][$key];
if ($key == 7) {
break;
}
}
return $list;
}
示例11: getOrigCache
protected function getOrigCache($src)
{
$localFile = $this->getBaseFile($src) . '.orig';
$url = self::isValidURL($src);
DiscoUtils::debug('About to download logo from [' . $src . ']');
DiscoUtils::debug('And will store locally at ' . $localFile);
if ($url !== null) {
DiscoUtils::debug('Logo found on valid location: ' . $url);
$imagecontent = url_get_contents($url);
if (empty($imagecontent)) {
return null;
}
file_put_contents($localFile, $imagecontent);
DiscoUtils::debug('Successfully obtained logo from the url');
return $localFile;
}
$imagecontent = self::isValidEmbedded($src);
if ($imagecontent !== null) {
file_put_contents($localFile, $imagecontent);
DiscoUtils::debug('Successfully obtained logo from embedded in metadata and stored a local cache');
return $localFile;
}
return null;
}
示例12: checkLink
function checkLink($url)
{
// $data = file_get_contents($url);
$data = url_get_contents($url);
}
示例13: sync_file
function sync_file($remote_url, $local_path)
{
$remote_contents = url_get_contents($remote_url);
if (strlen($remote_contents) == 0 or substr($remote_contents, 0, 1) != '{' and substr($remote_contents, 0, 5) != "<?php") {
return "<!-- Remote file not valid: {$remote_url} -->";
}
$local_contents = file_get_contents($local_path);
if (md5($remote_contents) == md5($local_contents)) {
return "<!-- No changes needed to {$local_path} -->";
}
if (file_put_contents($local_path, $remote_contents)) {
return "<!-- Synchronized {$local_path} -->";
} else {
return "<!-- Failed sync on {$path} -->";
}
}
示例14: header
include "includes/vars.php";
include "includes/functions.php";
$url = $_REQUEST['url'];
if (!$url) {
// header('Content-type: image/svg+xml');
// readfile('newimages/compact_disc.svg');
header("HTTP/1.1 404 Not Found");
exit(0);
} else {
$url = str_replace("https://", "http://", $url);
debuglog("Getting Remote Image " . $url, "TOMATO", 8);
$ext = explode('.', $url);
$outfile = 'prefs/imagecache/' . md5($url);
if (!file_exists($outfile)) {
debuglog(" Image is not cached", "TOMATO", 9);
$aagh = url_get_contents($url);
if ($aagh['status'] == "200") {
debuglog("Cached Image " . $outfile, "TOMATO", 9);
file_put_contents($outfile, $aagh['contents']);
} else {
debuglog("Failed to download " . $url . " - status was " . $aagh['status'], "TOMATO", 7);
// header('Content-type: image/svg+xml');
// readfile('newimages/compact_disc.svg');
header("HTTP/1.1 404 Not Found");
exit(0);
exit(0);
}
}
$mime = 'image/' . end($ext);
$convert_path = find_executable("identify");
$o = array();
示例15: get_urls_sitemap
/**
* Get urls from sitemap
*
* @param string $sitemap: url of sitemap.
* @param int $timeout: time out in seconds.
* @todo consider to use `simplexml_load_file()` and `simplexml_load_string()`.
* @link http://www.php.net/manual/en/function.simplexml-load-file.php
* @link http://php.net/manual/en/function.simplexml-load-string.php
*/
function get_urls_sitemap($sitemap, $timeout = TIMEOUT_OF_FETCHE)
{
// Get contents of sitemap
$xml = url_get_contents($sitemap, $timeout);
// Get URLs from sitemap
// @todo consider sub sitemap.
$urls = array();
if (preg_match_all("/\\<loc\\>(.+?)\\<\\/loc\\>/i", $xml, $matches) !== FALSE) {
if (is_array($matches[1]) && !empty($matches[1])) {
foreach ($matches[1] as $url) {
$urls[] = trim($url);
}
}
}
return $urls;
}