rumeye Posted January 11, 2013 Share Posted January 11, 2013 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 Quote Link to comment Share on other sites More sharing options...
The Letter E Posted January 14, 2013 Share Posted January 14, 2013 Have you checked to see if they even have their php compiled with simpleXML Support? Quote Link to comment Share on other sites More sharing options...
premiso Posted January 14, 2013 Share Posted January 14, 2013 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. Quote Link to comment Share on other sites More sharing options...
rumeye Posted January 15, 2013 Author Share Posted January 15, 2013 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.