Jump to content

error with SimpleXMLElement()


ravi181229

Recommended Posts

Hi there,

I am importing ustream feed and my script displays following warning:

 

Error type: Php Warning

Message: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: Entity: line 1: parser error : Start tag expected, '<' not found

 

My Code:

 

$link = 'http://ustream.tv/live.rss';

$rss_feed = file_get_contents($link);

$ustream = new SimpleXMLElement($rss_feed);

$casts = $ustream->channel->item;

foreach ($casts as $cast) {

  echo "<br>Title:".$cast->title;

  echo "<br>Link:".$cast->link;

  echo "<br>Embed:".$cast->embed;

}

 

Need help.

 

Thanks.

 

Link to comment
https://forums.phpfreaks.com/topic/112940-error-with-simplexmlelement/
Share on other sites

If allow_url_fopen is set to false, then file_get_contents will return nothing.

You could go by creating new SimpleXMLElement with the url as first parameter, and true as third. Not sure about second parameter, which is for libxml options.

Read the following for further information:

http://www.php.net/simplexml-element-construct

Hi Tchelo,

I have tried with the following code :

$link = 'http://ustream.tv/live.rss';

$rss_feed = file_get_contents($link);

$ustream = new SimpleXMLElement($rss_feed, NULL, TRUE);

 

it displays following warning:

Error type: Php Warning

Message: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: I/O warning : failed to load external entity "33bd4

 

If I echo $rss_feed, it shows proper content. problem is when it comes to SimpleXMLElement.

Well, if you are going to pass true to the third parameter, then the first should be the link, not its contents. Anyway, if you do get the correct contents, than there is something else wrong... I don't know how I can help right now, but I will try and research.

Tchelo,

 

I tried having first parameter as link also but it displays error.

Its written in the reference link (php.net) that we can pass string data as well when third parameter is TRUE.

 

I guess, you are right..there must be some other issue.

But please post the solution if you find.

 

Thanks a lot.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.