I am having some trouble with a url I encoded, I am getting this error and I don't know how to fix it.
Warning: file_get_contents(%27http%3A%2F%2Fapi.steampowered.com%2FISteamUser%2FGetPlayerSummaries%2Fv0002%2F%3Fkey%3D%27+..+%27%26steamids%3D%27+..) [function.file-get-contents]: failed to open stream: No such file or directory.
Is it not looking outside my home directory? Anyone know how to make the url function?
Any help would be awesome!
<?php
$url= "'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' .$apikey. '&steamids=' .$keyword.";
$string=file_get_contents(urlencode($url));
$json_a=json_decode($string,true);
$json_o=json_decode($string);
//array method
foreach($json_a[personaname] as $p)
{
echo '
<p>
Name: '.$p[response][players][personaname].'
';
}
?>
Assign your URL enclosed in only one type of quotes:
$url= "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=" . $apikey . '&steamids=' . $keyword;
Related
My case is, I want to scrap a website, which is success, and I'm using PHP cURL. The problem start when I want to use the DOM Parser to get the content I want. Here is the warning came out:
the error image is here
And the code I use is here. Before this code, I scrap a website using cURL, it's working, but just this part got error :
include 'simple_html_dom.php';
//Here is where I scraping, no need to show it
$fp = fopen(dirname(__FILE__) . '/airpaz.html', 'w');
//$html contain the page I scrap
fwrite($fp, $html);
fclose($fp);
$html_content = file_get_contents(dirname(__FILE__) . '/airpaz.html');
echo $html_content;
$html2 = new simple_html_dom();
$html2->load_file($html_content);
Hope you guys can help, thanks
It looks like you are trying to read a file 3 times:
$read_file = fread($fr, filesize(dirname(__FILE__) . '/airpaz.html'));
and:
$html_content = file_get_contents($read_file);
and:
$html2->load_file($html_content);
In the last two instances, instead of a file-name you pass html contents to the function so that will not work.
You should read the file only once and use string functions on the contents you receive. Or you open the url directly in $html2->load_file().
try this code
include 'simple_html_dom.php';
$html_content = file_get_html(dirname(__FILE__) . '/airpaz.html');
echo $html_content;
$html2 = new simple_html_dom();
$html2->load_file($html_content);
I was hoping I can get help with a problem I am having.
I'm using the php get meta tags function to see if a tag exist on a list of websites, the problem occurs when ever there is a domain without HTTP.
Ideally I would want to add the HTTP if it doesn't exist, and also I would need a work around if the domain has HTTPS here is the code I'm using.
I will get this error if I land on a site without HTTP in the domain.
Warning: get_meta_tags(www.drhugopavon.com/): failed to open stream: No such file or directory in C:\xampp\htdocs\webresp\index.php on line 16
$urls = array(
'https://www.smilesbycarroll.com/',
'https://hurstbournedentalcare.com/',
'https://www.dentalhc.com/',
'https://www.springhurstdentistry.com/',
'https://www.smilesbycarroll.com/',
'www.drhugopavon.com/'
);
foreach ($urls as $url) {
$tags = get_meta_tags($url);
if (isset($tags['viewport'])) {
echo "$url tag exist" . "</br>";
}
if (!isset($tags['viewport'])) {
echo "$url tag doesnt exist" . "</br>";
}
}
You could use parse_url() to check if the element scheme exists or not. If not, you could add it:
$urls = array(
'https://www.smilesbycarroll.com/',
'https://hurstbournedentalcare.com/',
'https://www.dentalhc.com/',
'https://www.springhurstdentistry.com/',
'https://www.smilesbycarroll.com/',
'www.drhugopavon.com/'
);
$urls = array_map(function($url) {
$data = parse_url($url);
if (!isset($data['scheme'])) $url = 'http://' . $url ;
return $url;
}, $urls);
print_r($urls);
You can use this to check if the domain has http
foreach($urls as $url){
if(strpos($url, "http") === FALSE) //check if the url contains http and add it to the beginning of the string if it doesn't
$url = "http://" . $url;
$tags = get_meta_tags($url);
}
Another simpler option would be to check for :// in the url
foreach($urls as $url){
if(strpos($url, "://") === FALSE) //check if the url contains http and add it to the beginning of the string if it doesn't
$url = "http://" . $url;
$tags = get_meta_tags($url);
}
Or you can use regex like Wild Beard suggested
you know whats funny, I thought it was because it had http but I put error_reporting(0); in my original code and it worked as I wanted it to haha.
I have the following code:
<?php
//first try
$url = 'http://www.omdbapi.com';
echo '<pre>';
print_r(file_get_contents($url));
echo '</pre>';
//second try
$url = 'http://www.omdbapi.com/?t=the dark night';
echo '<pre>';
print_r(file_get_contents($url));
echo '</pre>';
?>
The first try works fine. However, the second try give the following error message with no more details:
$file_get_contents(http://www.omdbapi.com/?t=the dark night): failed to open stream: HTTP request failed!
Note that,pc has windows 8.1 x64, I've tried both wamp server and xampp. I did make sure that both of $php.ini files have enabled both of the extentions $extension=php_openssl.dll and $extension=php_curl.dll
The documentation of file_get_contents say
Note: If you're opening a URI with special characters, such as spaces, you
need to encode the URI with urlencode().
So replace
$url = 'http://www.omdbapi.com/?t=the dark night';
with
$url = 'http://www.omdbapi.com/?t='.urlencode('the dark night');
Try to encode your url using urlencode:
$url = 'http://www.omdbapi.com/?t='.urlencode('the dark night');
echo '<pre>';
print_r(file_get_contents($url));
echo '</pre>';
I have googled for a day without a luck. Can anyone help please??
I have an AJAX request which loads more categories at home page. The code is
$json=array();
$template = new Template();
$template->data['categories'] = $this->data['categories'];
$html = $template->fetch($this->config->get('config_template') . '/template/common/category_load.tpl');
$json['success'] = $html;
$json['output'] = $this->render();
$this->response->setOutput(json_encode($json));
While I check the function it gives the correct output. But while trying to load through AJAX it gives the error saying
failed to open stream: Success in /var/www/html/boomrc/system/engine/controller.php on line 82
Have I done any mistake? I'm new to OpenCart.
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/category_load.tpl')) {
$this->template = $this->config->get('config_template') . '/template/common/category_load.tpl';
}
$json['content'] = str_replace("\r\n", "", $this->render());
echo json_encode($jdata);
Try this one..
Please use Browser-Debug-Console.
Be sure, that you doesn't do a cross-domain-request for your ajax.
There are some security-limitations, so you can't do cross-domain request for ajax.
Maybe post your controlle.php (or simplified code of it) here.
I am including two files in my index page:
$PageData = new Page_Data();
$PageData->title ="Welcome to my page";
$div= "<div class='login-form'>" . include_once "views/navigation.php" . include_once "controllers/login.php" . "</div>";
$PageData->content .=$div;
And I get these two errors.
Warning: include_once(controllers/login.php): failed to open
stream: No such file or directory in
C:\Users\kalle_000\Documents\KEA\3rd Semester\3rd
Module\Module_8\PHP_new\index.php on line 9
Warning: include_once(): Failed opening 'controllers/login.php'
for inclusion (include_path='.;C:\php\pear') in
C:\Users\kalle_000\Documents\KEA\3rd Semester\3rd
Module\Module_8\PHP_new\index.php on line 9 test content
What am I doing wrong? All the files are in the right folder where they should be. Any help appreciated!
include_once "views/navigation.php" . include_once "controllers/login.php" . "</div>"
This is basically evaluated as
include_once ("views/navigation.php" . (include_once ("controllers/login.php" . "</div>")))
That means first "controllers/login.php" . "</div>" is tried to be included, then views/navigation.php0 ("views/navigation.php" + result of the first include). That obviously won't work very well.
Further, the included content probably won't be concatenated into $div either, but output directly.
You probably want:
ob_start();
echo "<div class='login-form'>";
include_once "views/navigation.php";
include_once "controllers/login.php";
echo "</div>";
$div = ob_get_clean();
I changed the syntax to this:
$PageData = new Page_Data();
$PageData->title ="Welcome to my page";
$div= "<div class='login-form'>";
$div.= include_once ("views/navigation.php");
$div.= include_once ("controllers/login.php");
$div.= "</div>";
$PageData->content .=$div;
For some reason, the browser didn't understand the previous syntax, but gets this and now it works perfectly. Thanks for the help.