simplexml


Parsing RSS Feed with SimpleXML


When I Run this code:
<?php
$rss = simplexml_load_file('http://stackoverflow.com/feeds');
?>
<h1><?php echo $rss->title; ?></h1>
<ul>
<?php
foreach($rss->entry as $e) {
echo "<li><a href=\"".$e->link['href']."\">";
echo $e->title;
echo "</a></li>\n";
}
?>
</ul>
It generate following error:
Warning: simplexml_load_file(http://stackoverflow.com/feeds) [function.simplexml-load-file]: failed to open stream: Permission denied in /home/www/cheapflightshunt.co.uk/aaaa.php on line 2
Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "http://stackoverflow.com/feeds" in /home/www/cheapflightshunt.co.uk/aaaa.php on line 2
Warning: Invalid argument supplied for foreach() in /home/www/cheapflightshunt.co.uk/aaaa.php on line 7
My shared hosting is running with PHP5.2.17
Please provide the solution.
Thanks in advance.
Your code works perfectly. I suspect that your current settings doesn't allow fopen over url
Try checking that.
If you can't change that setting, try CURL, instead:
<?php
$ch = curl_init('http://stackoverflow.com/feeds');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);
$rss = new SimpleXMLElement($data);
?>
<h1><?php echo $rss->title; ?></h1>
<ul>
<?php
foreach($rss->entry as $e) {
echo "<li><a href=\"".$e->link['href']."\">";
echo $e->title;
echo "</a></li>\n";
}
?>
</ul>

Related Links

SimpleXML Sigle Depth Element with Attribute in Inline List
Copying CDATA between 2 xml files
PHP 7 simpleXML fatal error
SimpleXMLElement::__construct(): Entity: line 1: parser error : Start tag expected, '<' not found
Add xml attribute documentname
Pick shortest route with simpleXML
SimpleXML extract text between two tags
XML Node outside parent item
SimpleXMLElement cannot get the output
SimpleXML changing parsed decimals
can't navigate SimpleXMLElement data
PHP SimpleXML Load File with Null elements
Iterating through and editing a SimpleXML object by reference in PHP
Simplexml Insert into sub element
warning: simplexml_load_file(): I/O warning : failed to load external entity drupal [closed]
What's wrong with this code? SimpleXMLElement [closed]

Categories

HOME
maven
cakephp
ibm-bluemix
log4j
coq
hook
keycloak
plone
smarty
view
gis
google-oauth
tizen-web-app
infragistics
graphql
ckeditor
networkx
floating-action-button
qt-creator
msp430
iron-router
percona
lombok
telephony
autocad-plugin
abi
extjs5
mustache.php
devops
captiveportal
nhapi
objectanimator
r-raster
javascriptcore
language-concepts
http-referer
bower-install
espeak
starteam
grid.mvc
estimote
s
.net-4.6.2
chain-builder
qsslsocket
jquery-nestable
promela
dandelion
hls.js
dropbox-php
tizen-native-app
svmlight
aurelia-validation
recursive-datastructures
directory-structure
capacity
memory-alignment
redundancy
objective-c-swift-bridge
spring-android
slicknav
mongocsharpdriver
websitepanel
multiple-regression
angstrom-linux
persist
ford-fulkerson
r-tree
t4mvc
collapse
feedback
drawbitmap
method-parameters
nsight
angular-local-storage
key-management
device-orientation
javax.mail
dd
starcluster
hippomocks
seaside
mechanize-ruby
undefined-reference
typo3-neos
html4
django-nonrel
seed
javaspaces
errai
spring-portlet-mvc
gnu-prolog
deobfuscation
django-tagging
krl
android-sdk-2.1
mysql-error-1005
modelstate
vc90
sector
commodore
lzh
document-conversion

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App