php file_get_contents error when URL as variable -


i'm struggling weird problem file_get_contents().
first, code loads xml rss address. file_get_contents() fetch html using page address xml.

$url = 'http://www.moviejoy.com/rss/index.asp'; $rss = new domdocument(); $rss->load($url);  foreach ($rss->getelementsbytagname('item') $node) {     $link = $node->getelementsbytagname('link')->item(0)->nodevalue;     $html = file_get_contents($link);     print_r($html); } 

this code gives me error says:

warning: file_get_contents(http://www.moviejoy.com/qnam/view.asp?db=qna&num=2358) [function.file-get-contents]: failed open stream: no such file or directory in /[ ... ]/index.php on line 135

but!
when put url directly instead of $link, works. this:
$html = file_get_contents(http://www.moviejoy.com/qnam/view.asp?db=qna&num=2358);

i have no idea fix this. me, please!

you can see in rss source link in tag:

<link> http://www.moviejoy.com/qnam/view.asp?db=qna&amp;num=2387                </link> 

so there's new line before , after it. can "clean" link calling trim on it. add this:

$link = trim($link); 

right after

$link = $node->getelementsbytagname('link')->item(0)->nodevalue; 

Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -