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));
?>
Related
I need to check if a webpage outside of my site has a specific word on it. I’ve tried file_get_contents() but it doesn’t return anything. Is there any way I can do this in PHP?
edit: Here’s what I’ve tried:
$query = 'example';
$file = "https:// www.site.com/search?q=$query";
// tested url and it works, had to add space to post it
$contents = file_get_contents($file);
echo $contents;
I was expecting it to just output the entire page for me to use .includes() on later but it just doesn’t output anything.
Look into curl to get the contents of a web page. Then you can use preg_match to find the word.
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).
Okay so I have my PHP code: (I need help with the 4th line) More info down below the code.
Basicly I am trying to get code below. i am trying to put get part of url but it doesn;'t work
$oIMDB = new IMDB('<?ph p echo$_GET("m");?> ')
and on the 4th line i put the code
and the code doesn't work, how can i use it?
I think you mean this:
$oIMDB = new IMDB($_GET["m"]);
you shouldn't need the php scripting block inside the class call. Function parameters don't need quotes either unless you are using a literal string. Try
$oIMDB = new IMDB($_GET["m"])
Is there any way to save an XML attribute as a PHP variable and automatically place it in another http request? Or is there a better way to do that?
Basically, I send a server an http request, the code I get back looks something like this:
<tag one="info" two="string">
I need to save the string in attribute two and insert it in an http request that looks something like this:
http://theserver.com/request?method=...&id=123456
The '123456' ID needs to be the string in attribute 'two'.
Any help would be appreciated!
Thanks,
Jane
If you are 100% entirely absolutely completely TOTALLY sure that the content will always have that exact format, you can probably use regex as the other answers have suggested.
Otherwise, DOM isn't very hard to manage...
$dom = new DOMDocument;
$dom->loadXML($yourcontent);
$el = $dom->getElementsByTagName('A')->item(0); // presuming your tag is the only element in the document
if ($el) {
$id = $el->getAttribute('id');
}
$url = 'http://theserver.com/request?method=...&id=' . $id;
If you have a real example of the XML that you'll receive, please do post it and I'll adapt this answer for it.
If you can... send it in JSON. If you can't, and the only thing that is returned is that wee snippet, then I'd use regex to pull out the value.
Something like /.*two="([^"]+)".*/ should match everything, replace matches with '$1'
Otherwise use simplexml.
You could use:
<?php
$string = '<tag one="info" two="123456">';
if (preg_match('/<tag one="[^"]*" two=\"([^"]*)\">/',$string,$match)) {
$url = 'http://theserver.com/request?method=...&id=' . $match[1];
echo $url;
}
?>
Within the code below, how do I set VAR as some variable and then include it within the SimplePie code as the feed URL? The "feed" code is from the Simplepie PHP libary.
<?php
$VAR = "http://website.com/feed/";
$feed1 = new SimplePie();
$feed1->set_feed_url('$VAR');
$feed1->init();
?>
I m not sure about Simple Pie. But if you use single quotes it wont be processed. Try double quotes or better you dont need any quotes for that.
Try this :
$feed1->set_feed_url($VAR);