I tried everything to get the xml from the url, even smottt idea from PHP How to hit a url and download its xml , but didnt work for me.
my scenario;
URL that generates Dollar Exchange Rates:
nrb.org.np/exportForexXML.php?YY=2015&MM=03&DD=01&YY1=2015&MM1=03&DD1=01
Here: YY MM DD are the starting date and YY1 MM1 DD1 are the ending date of report. I believe , it generates an xml in unix time of Kathmandu, Asia. Everytime and second seperate xml file name.
Searched internet but nothing,
I want to display the result of xml in a page using php either by downloading the xml from the given url to my localhost folder or directly from web.
please help.
Thanks in Advance
Edited: Code I am using is
$url = "nrb.org.np/exportForexXML.php?YY=2015&MM=03&DD=01&YY1=2015&MM1=03&DD1=01";
$xml = new SimpleXMLElement($url, null, true);
foreach($xml->CurrencyConversionResponse as $CurrencyConversionResponse) {
echo $CurrencyConversionResponse->BaseCurrency . "<br />";
echo $CurrencyConversionResponse->TargetCurrency . "<br />";
echo $CurrencyConversionResponse->ConversionTime . "<br />";
echo $CurrencyConversionResponse->ConversionRate . "<br />";
}
And the error message is
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: I/O warning : failed to load external entity "nrb.org.np/exportForexXML.php?YY=2015&MM=03&DD=01&YY1=2015&MM1=03&DD1=01" in C:\xampp\htdocs\xml.php on line 4
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in C:\xampp\htdocs\xml.php:4 Stack trace: #0 C:\xampp\htdocs\xml.php(4): SimpleXMLElement->__construct('nrb.org.np/expo...', 0, true) #1 {main} thrown in C:\xampp\htdocs\xml.php on line 4
Add the http:// to the URL
$url = "http://nrb.org.np/exportForexXML.php?YY=2015&MM=03&DD=01&YY1=2015&MM1=03&DD1=01";
$xml = new SimpleXMLElement($url, null, true);
foreach($xml->CurrencyConversionResponse as $CurrencyConversionResponse) {
echo $CurrencyConversionResponse->BaseCurrency . "<br />";
echo $CurrencyConversionResponse->TargetCurrency . "<br />";
echo $CurrencyConversionResponse->ConversionTime . "<br />";
echo $CurrencyConversionResponse->ConversionRate . "<br />";
}
Related
I am using the setup, I download and setup package from github with link below:
https://github.com/graphaware/reco4php
I have also installed the php7 and neo7j they are running properly on localhost (ubuntu16.04).
I am getting error in browser:
Fatal error: Uncaught Error: Class 'GraphAware\Reco4PHP\Demo\Github\RecommendationEngine' not found in /var/www/html/recommendation_2/example.php:9 Stack trace: #0 {main} thrown in /var/www/html/recommendation_2/example.php on line 9
when hit example.php form browser.example.php file code below:
<?php
// example.php file
require_once __DIR__.'/vendor/autoload.php';
use GraphAware\Reco4PHP\Demo\Github\RecommendationEngine;
use GraphAware\Reco4PHP\RecommenderService;
$rs = RecommenderService::create("http://neo4j:idealindore#localhost:7474");
$rs->registerRecommendationEngine(new RecommendationEngine());
$stopwatch = new \Symfony\Component\Stopwatch\Stopwatch();
$input = $rs->findInputBy('User', 'login', 'jakzal');
$engine = $rs->getRecommender("github_who_to_follow");
$stopwatch->start('reco');
$recommendations = $engine->recommend($input);
$e = $stopwatch->stop('reco');
//echo $recommendations->size() . ' found in ' . $e->getDuration() . 'ms' .PHP_EOL;
foreach ($recommendations->getItems(10) as $reco) {
echo $reco->item()->get('login') . PHP_EOL;
echo $reco->totalScore() . PHP_EOL;
foreach ($reco->getScores() as $name => $score) {
echo "\t" . $name . ':' . $score->score() . PHP_EOL;
}
}
Can anybody help me how can I solve this issue?
You are getting this error because you did not use the right path to the classes.
Change This :
use GraphAware\Reco4PHP\Demo\Github\RecommendationEngine;
use GraphAware\Reco4PHP\RecommenderService;
to where you actually store These files.
RecommendationEngine.php
RecommenderService.php
Beside you also need to use these classes :
use GraphAware\Common\Cypher\Statement;
use GraphAware\Common\Type\Node;
use GraphAware\Reco4PHP\Context\Context;
use GraphAware\Reco4PHP\Engine\SingleDiscoveryEngine;
See This Link and follow the tutorial step by step to learn how to build a graph base recommendation system with Neo4J.
Also Check This Post if you have any problem with the tutorial.
I've been given data from a previous version of a website (it was a custom CMS) and am looking to get it into a state that I can import it into my Wordpress site.
This is what I'm working on - http://www.teamworksdesign.com/clients/ciw/datatest/index.php. If you scroll down to row 187 the data starts to fail (there should be a red message) with the following error message:
Fatal error: Uncaught exception 'Exception' with message 'String could
not be parsed as XML' in
/home/teamwork/public_html/clients/ciw/datatest/index.php:132 Stack
trace: #0
/home/teamwork/public_html/clients/ciw/datatest/index.php(132):
SimpleXMLElement->__construct('
Can anyone see what the problem is and how to fix it?
This is how I'm outputting the date:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<?php
ini_set('memory_limit','1024M');
ini_set('max_execution_time', 500); //300 seconds = 5 minutes
echo "<br />memory_limit: " . ini_get('memory_limit') . "<br /><br />";
echo "<br />max_execution_time: " . ini_get('max_execution_time') . "<br /><br />";
libxml_use_internal_errors(true);
$z = new XMLReader;
$z->open('dbo_Content.xml');
$doc = new DOMDocument;
$doc->preserveWhiteSpace = false;
// move to the first <product /> node
while ($z->read() && $z->name !== 'dbo_Content');
$c = 0;
// now that we're at the right depth, hop to the next <product/> until the end of the tree
while ($z->name === 'dbo_Content')
{
if($c < 201) {
// either one should work
$node = simplexml_import_dom($doc->importNode($z->expand(), true));
if($node->ClassId == 'policydocument') {
$c++;
echo "<h1>Row: $c</h1>";
echo "<pre>";
echo htmlentities($node->XML) . "<br /><br /><br /><b>*******</b><br /><br /><br />";
echo "</pre>";
try{
$xmlObject = new SimpleXMLElement($node->XML);
foreach ($xmlObject->fields[0]->field as $field) {
switch((string) $field['name']) {
case 'parentId':
echo "<b>PARENT ID: </b> " . $field->value . "<br />";
break;
case 'title':
echo "<b>TITLE: </b> " . $field->value . "<br />";
break;
case 'summary':
echo "<b>SUMMARY: </b> " . $field->value . "<br />";
break;
case 'body':
echo "<b>BODY:</b> " . $field->value . "<br />";
break;
case 'published':
echo "<b>PUBLISHED:</b> " . $field->value . "<br />";
break;
}
}
echo '<br /><h2 style="color:green;">Success on node: '.$node->ContentId.'</h2><hr /><br />';
} catch (Exception $e){
echo '<h2 style="color:red;">Failed on node: '.$node->ContentId.'</h2>';
}
}
// go to next <product />
$z->next('dbo_Content');
}
} ?>
</body>
</html>
The error message you're getting "String could not be parsed as XML" means that the XML parser found something in the input data that was not valid XML.
You haven't shown us the data, so I can't tell you exactly what is invalid, but something in there is failing to meet the strict rules for XML parsing. There are any number of possible reasons for this.
If I had to stick my neck out on the line and guess, I'd say the most common reason cause of bad XML in the middle of a file that is otherwise okay would be an unescaped & when it should be the & entity code.
Anyone creating their XML using a proper XML writer shouldn't have this issue, but I've come across plenty of cases where people don't bother using an XML writer and just output raw XML as text and have forgotten to escape the entities, which means that that the data is fine until you come to a company name with an & in it.
If it's as simple as that, and it's a one-off import, you may be able to fix the file manually in a text editor.
However that's just a guess. You'll need to actually examine the XML file for yourself to see the problem. If you can't see the problem visually, I'd suggest using a GUI XML tool to analyse the file.
Hope that helps.
[EDIT]
Okay, I just took a better look at the data in the link you gave, and on thing sticks out like a sore thumb....
encoding="utf-16"
I note that all the data that has worked was using UTF-8, and all the data that has failed is using UTF-16.
PHP is generally fine with UTF-8, but it won't cope very well at all with UTF-16. So it's fairly clear that this is your problem.
And, to be honest, there's really no need to ever use UTF-16, so the solution here is to switch to UTF-8 encoding for everything.
How easy that is for you to do, I can't say, but worst case I'm sure you could find a batch convertion tool.
Hope that helps.
having an annoying issue with getting xml data from a url
if i set "$file_show_title" to a single word (comes from the url passed from another page) then all works fine. if if "$file_show_title" is 2 words (tried encoding the url also) then it failed to find the address.
im not the best at explaining but i hope that this is enough for someone to help me please
thanks
$url = file_get_contents("http://www.thetvdb.com/api/GetSeries.php?seriesname=".$file_show_title);
$xml = simplexml_load_string($url);
$seriesid = $xml->Series[0]->seriesid;
$seriesbanner = $xml->Series[0]->banner;
$seriesname = $xml->Series[0]->SeriesName;
$serieslanguage = $xml->Series[0]->language;
$seriesfist_aired = $xml->Series[0]->FirstAired;
$seriesoverview = $xml->Series[0]->Overview;
echo '<img src="/images/'.$seriesbanner.'">'."<br />";
echo $seriesname."<br />";
echo $seriesid."<br />";
echo $serieslanguage."<br />";
echo $seriesfist_aired."<br />";
echo $seriesoverview."<br />";
What you needed was urlencode Please see http://php.net/manual/en/function.urlencode.php for more information
Example
$url = file_get_contents("http://www.thetvdb.com/api/GetSeries.php?seriesname=" . urlencode("Prison Break"));
Now Use
$url = file_get_contents("http://www.thetvdb.com/api/GetSeries.php?seriesname=" . urlencode($file_show_title));
I hope it helps
code.google.com's API for PHP
I have used this function : function printVideoEntry($videoEntry) and got
Video ID: XXXXXXXXXXXXXXXXXXXXXXXXXX Watch page:
http://www.youtube.com/watch?v=YYYYYYYYYYYYYY&feature=youtube_gdata_player
Flash Player Url:
http://www.youtube.com/v/YYYYYYYYYYYYY?version=3&f=playlists&app=youtube_gdata
If I pass given video id it gives me error:
Uncaught exception 'Zend_Gdata_App_HttpException' with message
'Expected response code 200, got 400 Invalid id'
And if I pass YYYYYYYYYYYYYYYYY from Watch page and Flash Player Url [both are same] I'm getting it what I need.
Help is much appreciated, Thanks in advance.
Using this function for getting video entries
function printVideoEntry($videoEntry) {
echo "<div onclick=\"ytvbp.presentVideo('".$videoEntry->getVideoId()."')\" >";
echo 'Video: '.$videoEntry->getVideoTitle() . "<br>";
echo "</div>";
echo 'Video ID: ' . $videoEntry->getVideoId() . "<br>";
echo 'Watch page: ' . $videoEntry->getVideoWatchPageUrl() . "<br>";
echo 'Flash Player Url: ' . $videoEntry->getFlashPlayerUrl() . "<br>";
}
I'm calling print video function from
function getAndPrintPlaylistVideoFeed($playlistListEntry) {
$yt = new Zend_Gdata_YouTube();
$playlistVideoFeed = $yt->getPlaylistVideoFeed($playlistListEntry->getPlaylistVideoFeedUrl());
foreach ($playlistVideoFeed as $playlistVideoEntry) {
$getandprintplaylistvideofeed_array[] = printVideoEntry($playlistVideoEntry);
}
$videoEntry should be a VideoEntry-object, which you can get based on an ID:
$videoEntry = $yt->getVideoEntry('the0KZLEacs');
Then you could call the function and set that as a parameter:
printVideoEntry($videoEntry);
Or you could edit the first lines of printVideoEntry:
function printVideoEntry($videoId) {
$videoEntry = $yt->getVideoEntry('the0KZLEacs');
//...
}
Check out the docs to see what information you can squeeze out of a VideoEntry =)
I do not know if it is a global Zend property storage system or what, but when I create the following kind of code:
$serviceName = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
$client = Zend_Gdata_ClientLogin::getHttpClient($username, $pass, $serviceName);
// update the second argument to be CompanyName-ProductName-Version
$gp = new Zend_Gdata_Photos($client, "Google-DevelopersGuide-1.0");
$userFeed = $gp->getUserFeed("default");
foreach ($userFeed as $userEntry) {
echo $userEntry->title->text . "<br />\n";
}
I cannot seem to get all of the attributes for the specified $userEntry. When I do print_r, it just gives me the structure of the element, not the actual data.
My question is how do I get a list containing items such as "title" for $userEntry?
Thanks a million in advance!
it's not exactly an answer, but have you tried to debug using the lines below?
} catch (Zend_Gdata_App_HttpException $e) {
echo "Error: " . $e->getMessage() . "<br />\n";
if ($e->getResponse() != null) {
echo "Body: <br />\n" . $e->getResponse()->getBody() .
"<br />\n";
}
// In new versions of Zend Framework, you also have the option
// to print out the request that was made. As the request
// includes Auth credentials, it's not advised to print out
// this data unless doing debugging
// echo "Request: <br />\n" . $e->getRequest() . "<br />\n";
} catch (Zend_Gdata_App_Exception $e) {
echo "Error: " . $e->getMessage() . "<br />\n";
}
gl
Paulo Bueno.
Edit: See also this post Zend_Gdata_Photos listing all albums and photos.