I'm getting a lot of errors when I browse a clients site securely that have to do with the simplexml_load_file function. Here's an example:
Warning: simplexml_load_file() [function.simplexml-load-file]: https://xxxxxxxx/settings.xml:1: parser error : Document is empty in /xx/xx/xx/xx/xx/ on line 0
The site is on a dedicated server from SingleHop. It only happens when I browse the site with https://, and works fine when browsed with http://.
Seems to be loading the XML file just fine with https:// as well:
https://consumerstrust.org/wp-content/plugins/easyfanpagedesign/framework/settings.xml
The XML is parsed from a class:
public function efpd_load_settings($xmlfile){
$xmlparse=simplexml_load_file($xmlfile);
$settings=array();
$setint=0;
foreach($xmlparse->option as $xml){
$option[$setint]=(array)$xml;
array_push($settings,$option[$setint]);
$setint++;
}
return $settings;
}
and ran like this:
$efpdxml=plugins_url('settings.xml',__FILE__); // plugins_url() is a WP function - returns the value just fine.
$efpdsettings=Efpd::efpd_load_settings($efpdxml);
Is this something that happens commonly? Also anything to fix it? If you need any more info to help me solve this just let me know and I will provide it.
Thanks.
I just confirmed file_get_contents works just fine.
$content = file_get_contents("https://consumerstrust.org/wp-content/plugins/easyfanpagedesign/framework/settings.xml");
if ( empty($content) ) {
die('XML is empty');
}
$xml = simplexml_load_string($content);
Edit
Using simplexml_load_file with https URL also worked for me. This is only an alternative.
I figured out my own problem, but thank you to those of you who tried helping me. I appreciate it.
My solution:
This was being run in WordPress, so I really should have posted this in the WPSE site, but I don't blame anyone for not knowing all about WP from this site if they didn't.
The function plugins_url() should not have been used to define the path to the XML file, I should have been using dirname(__FILE__).'/settings.xml' - which is pretty obvious as to why if you know how plugins_url() works, I overlooked it completely but in the end solved my problem.
Related
My copy code doesnt work for some reason. Tried several things.
this is the code that I am trying to use
$fb_foto_url = $userData['picture']['data']['url'];
$plaats = '/assets/images/profielfotos/fiel.jpg';
copy($fb_foto_url, $plaats);
The $userData['picture']['data']['url']is getting filled with this for example: https://lookaside.facebook.com/platform/profilepic/?asid=113831052838678&height=200&width=200&ext=1527931138&hash=AeSlklMNX6l4Uanh
I need that to get stored in on the server. But it isn't working for some reason. I am doing something wrong but can't figure out what.
If someone can help me with this code, would be nice.
Try this:
file_put_contents($plaats,file_get_contents($fb_foto_url));
PHPs copy function expects path's, not URL's.
A (server-) path is a directory name on the machine the PHP code is executed on.
An URL is a virtual name that may or may not point to such a physical path or is resolved dynamically.
Example:
The server path to a websites images might be /var/www/example.org/assets/images/, while the URL is http://example.org/assets/images/.
http://php.net/manual/en/function.copy.php
I am using simple_html_dom script to gather certain information from external pages.
The script I have been using worked pretty well until today. I tried to look for where the error came from and it seems the file_get_html function is not working anymore, only on certain URLs.
The basic code I am using is:
<?php include_once('../simple_html_dom.php');
echo file_get_html('http://www.hltv.org/match/2295100-')->plaintext; ?>
When executing this, I have a blank page on my OVH shared server. It seems the page returns a 503 error, even if the page actually exists. I am able to extract the content of the page from other servers (like AWS) however. What troubles me is that it's been working for 4 months now without any issue.
I made sure the MAX_FILE_SIZE of the simple_html_dom was increased but could not find any solution to this.
Any idea to solve the issue?
Thanks!
Try this:
<?php
include_once('../simple_html_dom.php');
$result = file_get_html('http://www.hltv.org/match/2295100-');
echo $result->plaintext;
?>
Okay - simple details first:
Feed URL: http://feeds.wired.com/wired/index
When I access this directly through simplepie and not CraftCMS, the feed loads without issue. When I access it through the CMS template system it throws an error saying the returned XML is effectively garbage. Looking into this, its because the feed host is returning a page not found.
I have dug through the code to find out why it is a page not found on a valid URL and found that in the file:
/library/simplepie/registry.php
public function &create($type, $parameters = array()) (around line 160)
Now in this function I see that a new reflection class is created and new InstanceArgs are sent the parameters. At this point the Feed URL gets changed from:
http://feeds.wired.com/wired/index
to
http://feeds.wired.com/wired/index?#
Effectively this new URL with the added ?# on the end is causing the feed site to return a page not found. And hence all my errors...
This is beginning to hit the end of my abilities - and I would like to know what is causing the ?# to be added and if there is a way to prevent it? Or any other possible solutions to my problem.
I can't explain why it works outside of Craft and not inside, but it definitely looks like a SimplePie bug to me.
Just created an issue and pull request with the fix for them (https://github.com/simplepie/simplepie/issues/366) and will see about updating it in Craft itself.
Update: looks my fix didn't broke some of their tests, so we won't be putting that into Craft, but they have acknowledged it needs to be fixed.
I have been trying to load a number of XML files into a PHP page using a simple load string. Strange as this might sound, not one loads, and all return as empty.
I can load them using $xmldoc = new DomDocument( '1.0' ); and I can view all directly in the browser. I'm getting really frustrated because I can't see why they should fail to load.
I am using offline development - Win7 proff, XAMPP Version: 1.8.1 with PHP 5.4 loaded.
Example of my simple loading code:
$xml = simplexml_load_string('menu45.xml');
if ( !$xml ) {
echo "empty!!!!";
// return 'Error';
}
I am hoping someone will let me know if there is a problem with using a simple load string on a Windows machine or if there's a bug in PHP 5.4, or XAMPP has issues with it, or something.
I've Google'd and read everything I could for an 18 hour stint without joy. Any suggestion would be greatly appreciated.
simplexml_load_string() loads strings, not files.... and "menu45.xml" isn't a well formed xml string. Try simplexml_load_file() instead.
I am using a very cool php library(whatever it is called) called SimplePie. I am using the latest version.
I have this code:
$url = 'http://www.seobook.com/feeds.shtml';
$SimplePieFeed->set_feed_url($url);
$SimplePieFeed->force_feed(true);
$SimplePieFeed->enable_order_by_date(true);
$success = $SimplePieFeed->init();
if( !$SimplePieFeed->error() ) {
foreach( $SimplePieFeed->get_items() as $item ) {
......
}
} else {
print_r( $SimplePieFeed->error() );
}
Why is it that when I run this code I'm getting this kind of error:
This XML document is invalid, likely due to invalid characters. XML error: not well-formed (invalid token) at line 8, column 76
I try to run this one on Simplepie's demo and everything is going well. Why is it that when I run it on my end i'm having that kind of error? Is it because of a cache? I noticed that Simplepie is storing feeds in a cache. I have tried $SimplePieFeed->enable_cache(false); but still i'm getting that error. I'm not even sure if that's related to that kind of error. LOL!
Your help would be greatly appreciated and rewarded! :Thank you very much!
Simple there is problem in your xml file you should remake the .xml file,if you are using wordpress simple use plugin called google site maps its pretty good.
If you using some thing else like php, or html base site you should make valid xml document maker like some listed here,
xml-sitemaps.com
xmlgrid.net (editor viewer)
web-site-map.com
May it help you little in your case.