0

Afternoon,

I am using PHP Zend to search twitter API in order to find tweets with links, I can get the URL in the tweets using the entities array but I need to display the page title of the URL.

I am using DOMDocument() the following code below to get the title, is there any other way to get the URL title because it take an age for the page to load due to the pinging all the URL's or is there some info in the twitter response I am missing?

function getTitle($Url){
        $urlContents = file_get_contents($Url);
        $dom = new DOMDocument();
        @$dom->loadHTML($urlContents);

        $title = $dom->getElementsByTagName('title');

        return $title->item(0)->nodeValue; // "Example Web Page"            
    }

Thanks in advanced!

J.

2

2 Answers 2

0

If the following is indicative of the results you are working with.

10.    {
11.      "created_at":"Thu, 06 Oct 2011 19:36:17 +0000",
12.      "entities":{
13.        "urls":[
14.          {
15.            "url":"http://t.co/L9JXJ2ee",
16.            "expanded_url":"http://bit.ly/q9fyz9",
17.            "display_url":"bit.ly/q9fyz9",
18.            "indices":[
19.              37,
20.              57
21.            ]
22.          }
23.        ]
24.      }

Then it looks like some version of what you're already doing is what you need. You can cache it either in a MySQL database or a flat-file. If you're not familiar with either of those, make Google your friend. Cache won't help initial load time, but will help the next time someone accesses the page

You might consider letting the page load without titles, then fill them in with an AJAX call.

3
  • TecBrat Yes this is the data I get. But I need the page title any thoughts. ?
    – John Jones
    Feb 21, 2012 at 19:08
  • Then it looks like some version of what you're already doing is what you need. You can cache it either in a MySQL database or a flat-file. If you're not familiar with either of those, make Google your friend. Cache won't help initial load time, but will help the next time someone accesses the page.
    – TecBrat
    Feb 22, 2012 at 0:07
  • You might consider letting the page load without titles, then fill them in with an AJAX call.
    – TecBrat
    Feb 22, 2012 at 3:19
0

because it take an age for the page to load due to the pinging all the URL's

So you're loading all tweets upon a page view and then resolving all links? Yes, that'll take a while. You should store the URL's and their titles somewhere, say in a database, so you can quickly look them up again.

1
  • Excuse my ignorance but how would I do this? Grab the titles on inital load and then store tweet id, title and URL and when page loads again check if title stored in db by using tweet id?
    – John Jones
    Feb 13, 2012 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.