Go4Expert (http://www.go4expert.com/)
-   PHP (http://www.go4expert.com/forums/php/)
-   -   Get the title of the url (http://www.go4expert.com/forums/title-url-t1179/)

coderzone 12Aug2006 17:57

Get the title of the url

I am looking for a code snippet that can get me the title of the url I enter.

something like if I pass

It should return Go4Expert - Begining with PHP

I have checked the internet and seen that curl of php can be useful but could not use it in a very good sense as I am not a PHP expert.

pradeep 14Aug2006 11:23

Re: Get the title of the url
We can use Regular Expressions to get the title of a page, see the PHP code snippet below which extracts the title of page who's URL you specify.

Code: PHP

$url = "http://www.go4expert.com/showthread.php?t=2";
$file = file($url);
$file = implode("",$file);

    print "The title of $url is <b>$m[1]";
    print "The page doesn't have a title tag";

shabbir 14Aug2006 20:24

Re: Get the title of the url
I have added an extra bit of condition
Code: PHP

if (@fclose(@fopen($rightlink, "r")))

so that if the link is not reachable you dont have to open the file.

All times are GMT +5.5. The time now is 01:21.