Click to See Complete Forum and Search --> : Get the title of a webpage with a url


deep-wood
01-27-2008, 11:16 AM
I have a url field, and i would like to be able to get the title of the webpage when submitting.

Im aware of the function to get the page contents (cant remember the actual function name...), and with that i could grab the url, but if the source code is massive would'nt that be very resource hungy?

Is there a better way?

beahawk
01-27-2008, 06:41 PM
You would either have to have the page title in a php variable already or download the source of the page and extract it that way. The latter being much more long winded.

andre4s_y
01-28-2008, 09:15 AM
I think it is depend on the function that you use to get the page contents;
You can use
1. File system functions, such as fopen() or file_get_contents()
2. Curl functions, or
3. Socket functions..

the function that you use to fetch the page title
You can use :
1.String functions or
2.Regex, such as preg_match()

and.. how big is the targeted page..

All function there need resources..
Up to you now... want to use it or leave it...??? ;)

deep-wood
01-28-2008, 12:16 PM
well thats the thing, its user input. the page could be HUGE.

What are the 'curl' and 'socket' functions, never heard/used them

andre4s_y
01-28-2008, 08:55 PM
well...
i can say that fopen() and file_get_contents() [file system functions] are the easiest functions to get the page content.. but in my experience, those functions are slow.. so much chance to failed(based on indonesian internet connection :P)..
Curl is better... faster.. configurable.. higher chance... but more complicated..
than above functions.
Socket is most complicated... highest chance..
When file system function exhausted, curl can do.. when curl exhausted, socket can do... ;)

Want to make some comparison with me??
Come on.. just for fun...
You make your own code with file system functions, and i remake your code with curl or socket...
and then we compare it... ;)
Agree???