CodeIgniter Forums

Full Version: Get Remote Page Title
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[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;
    }

El Forum

[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

El Forum

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

El Forum

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

El Forum

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

El Forum

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

El Forum

[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!