Welcome Guest, Not a member yet? Register   Sign In
Get Remote Page Title
#1

[eluser]Dregond Rahl[/eluser]
Does this method seem effective? Anything I can do to improve it? I only need the title.

Code:
function _get_page_title($url)
    {
        $ch = curl_init($url);

        curl_setopt($ch, CURLOPT_HEADER, 0);

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

        $html = curl_exec($ch);

        curl_close($ch);

        if (preg_match('/&lt;title&gt;(.*)<\/title>/i', $html, $match))
        {
            return $this->input->xss_clean($match[1]);
        }

        return FALSE;
    }
#2

[eluser]Wuushu[/eluser]
Hi, if you're going to use the data for display, it's always best practice to save the data to file/db/whatever so that on second+ lookups, you will not have to hit whoever's server it is that you're hitting - again.

Just my 0.02
#3

[eluser]Dregond Rahl[/eluser]
Yeah its stored in a database, this is just the getting function =]
#4

[eluser]OES[/eluser]
Hi

Not sure if you still need this but I just posted on my blog a helper for Screen Scrapping.

Would make your code alot less thanks to simple html dom :-).

Check it out.
#5

[eluser]Dregond Rahl[/eluser]
[quote author="OES" date="1245303409"]Hi

Not sure if you still need this but I just posted on my blog a helper for Screen Scrapping.

Would make your code alot less thanks to simple html dom :-).

Check it out.[/quote]

Thanks for this =], the reason why i used cURL was because my test sever is shared so it doesn't support URL file access, does Simple HTML DOM work still ?

Thanks, this might be useful for when i move to my real server.
#6

[eluser]cahva[/eluser]
Funny that they let you use curl but not URL file access. Curl extension has had more holes than a swiz-cheese Smile Forbidding url access with include,require etc. is perfectly understandable but when using file_get_contents, fopen etc. it really is not necessary.
#7

[eluser]Phil Sturgeon[/eluser]
One interesting option that I have never found time to look at is htmlSQL.

Theoretically this could be made into a DB driver for using limited ActiveRecord on XML. Wouldn't that be fun!




Theme © iAndrew 2016 - Forum software by © MyBB