charliebobgordon Posted July 15, 2012 Share Posted July 15, 2012 I've setup a PHP script at the bottom of my homepage on this website. It will grab the three most recent text posts from my blog and display a summary. It's setup to check for updated content every hour (cache). http://charlieswebsites.co.uk/fearofmobs/site It works good, but how can I make sure that it only ever returns <p> tags? Sometimes video iframes are embedded and images at the beggining of posts, and as you can see it posts those. I only want textual content returned. The script in use is: <?php $cachefile_blog = 'blogposts.txt'; $cache_timer = 3600 + @filemtime($cachefile_blog);// files timestamp + 3600 seconds if (file_exists($cachefile_blog) && time() < $cache_timer ) { // do nothing if file is fresh } else { // go get latest results $data = file_get_contents("http://blog.fearofmobs.com/api/read?type=post&type=post&num=3"); // overwrite the cached file with new data $fh = fopen($cachefile_blog, 'w') or die("can't open file"); fwrite($fh, $data); fclose($fh); } // read the cached file $request_url = file_get_contents($cachefile_blog); $xml = simplexml_load_string($request_url); ///simplexml_load_string --- for local files ///simplexml_load_file --- for URLS $cpost = $_GET["post"]; $tumblename = 'fearofmobs'; if (is_numeric($cpost)){ $request_url = 'http://' . $tumblename . '.tumblr.com/api/read?id=' . $cpost; $xml = simplexml_load_file($request_url); if($xml === FALSE){ } else { foreach ($xml->posts->post as $post) { }}} else { $request_url = 'http://' . $tumblename . '.tumblr.com/api/read?num=3&type=post'; $xml = simplexml_load_file($request_url); foreach ($xml->posts->post as $post) { $title = $post->{'regular-title'}; $body = $post->{'regular-body'}; $aname = $post['id']; $tlink = 'http://' . $tumblename . '.tumblr.com/' . $post['id']; $small_post = substr($body,0,132); echo '<div class="post"><a href="'.$tlink.'"><h4 class="post_title">'.$title.'</h4></a>'.$small_post.'…</p><span class="post_link"><a href="'.$tlink.'">Continue reading »</a></span></div>'; } } ?>'; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/265713-excluding-image-and-video-content-from-recent-tumblr-posts-script/ 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.