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
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. 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.