So I am trying to open an image from a URL using PHP but nothing seems to work. Here is my code. All i get is a blank box and I have tried with multiple links.
This is what I get for any URL I use. Any ideas? Any responses are greatly appreciated
<?php
header('Content-type: image/jpeg;');
$p = 'https://cdn.shopify.com/s/files/1/0094/2252/products/KithxAspenUltraBoostMidMulti-1_grande.jpg?';
$a = file_get_contents('$p');
echo $a;
?>
Don't use single qoutes, in this case, because then your $p var get litteral value (just string :$p)
, you need this:
$a = file_get_contents($p);
(or double quotes).
Related
I have a php page which get response from another page as shown:
while($response!=200)
{
$response = include 'xyz.php?one='.$one.'&two='.$two.'&three='.$three.'';
}
But my link always get's something like:
domainname.com/xyz.php?one=content&two=content&three=content
And due to & getting replaced by & I am getting the page not found issue.
I have tried using %26 and directly putting & instead of &, all in vain.
Is there any other simple solution besides using string replace function of PHP to remove & and replace it with &
Check out html_entity_decode
$response = html_entity_decode($response)
I ran a test based on the code you sent and I don't have a problem. That suggests you have something auto-magical going on in your *.ini file (magic quotes, maybe... ugh...). Try to create the string simply as a variable to remove it from the filename context and echo it out to be sure it's right, then use the variable with your include.
$one = 'abc';
$two = 'def';
$three = "ghi";
$file= 'xyz.php?one='.$one.'&two='.$two.'&three='.$three;
echo "\n\n".$file;
$response = include $file;
You can't use URL parameters when accessing a local file, they have to go through the webserver. Try:
$response = file_get_contents("http://localhost/path/to/xyz.php?one='.$one.'&two='.$two.'&three='.$three);
I'm trying to get file content from a php file.
$content = file_get_contents('test.php');
var_dump($content);
//outputs
addUser();
test.php
<?php
$client->addUser();
Why is file_get_contents removing $client-> ?
It's probably not removing anything, but you're reading the result in a browser, and the browser thinks that anything between a < and a > is a html tag.
Use the "view source" function in your browser to see the whole thing.
You've got 2 HTML brackets <>
Try this
echo htmlentites($content);
I have two php files, one index.php
<?php
include ‘Play.php’;
$temp = first(HH);
echo $temp;
?>
second Play.php
<?php
function first($string)
{
return $string;
}
?>
if i remove $temp = first(HH); from the first file then it works, if i include it, the index.php don't work (don't show anything on the screen when i call it within safari.
I know its going to be obvious but what am i doing wrong? Both files are in the same file directory.
Thanks
Use the right kind of quotes around your string for the include. " or ' not ‘ and ’.
The use of typographic quotes like that suggests you may be trying to write code with a word processor. Don't do that; get a text or code editor instead.
Your function is right but the way you are calling your function is not correct.And the way you are including the file is incorrect. You should include your file in quotes like "" or '' . You have to enclose the string in quotes "". Use the code below in index.php
<?php
include 'Play.php';
$temp = first("HH");
echo $temp;
?>
I hope this helps you
include expects double quotes " so change that in, your code and it should work.
include "Play.php";
Kindly change
$temp = first(HH); to $temp = first("HH");
its is because your function tack string as a parameter you should send a string
This is my code:
<?php
$url = "https://api.datamarket.azure.com/opendata.rdw/VRTG.Open.Data/v1/KENT_VRTG_O_DAT?$filter=Kenteken%20eq%20%2701GBB1%27";
$xml = simplexml_load_file($url);
?>
Im trying to get this .XML file into my $url. The problem is that its using
https://api.datamarket.azure.com/opendata.rdw/VRTG.Open.Data/v1/KENT_VRTG_O_DAT and not the one with the filter:
https://api.datamarket.azure.com/opendata.rdw/VRTG.Open.Data/v1/KENT_VRTG_O_DAT?$filter=Kenteken%20eq%20%2701GBB1%27
Why is it not taking the URL i entered there? When i open the URL in my browser i get the filtered one but when i run the code itll give me the other .XML.
I hope someone can help me.
You are using double quotes, so php will interpret $filter as a (probably undefined...) variable.
You can avoid that using single quotes:
$url = 'https://api.datamarket.azure.com/opendata.rdw/VRTG.Open.Data/v1/KENT_VRTG_O_DAT?$filter=Kenteken%20eq%20%2701GBB1%27';
Use single quotes.
Then re-read the docs
Have you tried this?
<?php
$url='https://api.datamarket.azure.com/opendata.rdw/VRTG.Open.Data/v1/KENT_VRTG_O_DAT? $filter=Kenteken%20eq%20%2701GBB1%27';
$xml = new SimpleXMLElement(file_get_contents($url));
?>
I have a txt file on the server which contains 10 lines of text. The text file is rewritten sometimes, and I get new lines using "\r\n". My problem shows when I want to load the lines in javascript variables. I do it like this, but this work only for numbers or for the last line of the file, because its not using the breakline tag: var x = '<?php echo $file[0]; ?>';
Ive tried to alert(x) but it`s not working.... (working only if I read the last line)
Any idead ?
I'm not sure I completely understand the question, but you should be able to use json_encode() which will escape the data appropriately:
var x = <?php echo json_encode($file[0], JSON_HEX_TAG); ?>;
As others have said, you can trim() the data to remove trailing whitespace/line breaks. You should still use json_encode() in addition to this as otherwise it will still be possible to break out of the javascript string (e.g. by sending a string with a quote in).
You want trim():
var x = '<?php echo trim($file[0]); ?>';
But if you read the file(), you could array_map() it with trim() and then keep doing what you're doing:
$values = array_map("trim", file('input-file.txt'));
You might consider what happens if someone decides to include a single quote in the variable with this approach.
EDIT: Then you can add json_encode() as suggested in other answers:
var x = <?php echo json_encode($file[0]); ?>;
Thanks for all! The I solved the problem with the help of artlung and Richard JP Le Guen:
var x = <?php rtrim($file[0]); ?>