Jump to content

Problem with PHP/XML with Tumblr


rumeye

Recommended Posts

I am trying to pull XML content from Tumblr into my website. This is the following code that i have problem with:

 

 

<?php

$request_url = "http://jeffhui.tumblr.com/api/read?start=0&num=1";

$xml = simplexml_load_file($request_url);

$title = $xml->posts->post->{'regular-title'};

$post = $xml->posts->post->{'regular-body'};

$link = $xml->posts->post['url'];

$small_post = substr($post,0,420);

 

echo '<h1>'.$title.'</h1>';

echo '<p>'.$small_post.'</p>';

echo "…";

echo "</br><a target=frame2 href='".$link."'>Read More</a>";

?>

 

Above code work fine within my internal web server, but when I FTP it to my hosting company it stop working. (My hosting company is CGI-BIN + PHP 4 & 5 Support)

 

Jeff

Link to comment
https://forums.phpfreaks.com/topic/273039-problem-with-phpxml-with-tumblr/
Share on other sites

My bet is going to be that they have fopen url wrappers turned off for security reasons. They will most likely offer curl, so I would use curl to fetch the page, and then use the load_string for simplexml to pull in the data and process it. 

Just checked with my Hosting company, and they did have url wrappers turned off. So this suggestion by Premiso work, with the following code:

 

 

$url = "http://jeffhui.tumblr.com/api/read?start=0&num=1";

 

$ch = curl_init();

$timeout = 5; // set to zero for no timeout

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

$result = curl_exec($ch);

curl_close($ch);

 

$xml = simplexml_load_string($result);

 

Myself prefer simplexml, so I just called my Hosting company and they did that on there server:

 

allow_url_fopen = On

allow_url_include = On

 

Now everything back to normal =)

 

Thank You guys!

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.