Maverickb7 Posted March 22, 2007 Share Posted March 22, 2007 I was wondering if someone could tell me the easiest way to obtaining the page title of a specific url? I've tried to use fopen and those functions but I got the below error. Warning: fopen() [function.fopen]: URL file-access is disabled in the server configuration in /home/web/ute.php on line 2 Quote Link to comment https://forums.phpfreaks.com/topic/43773-obtaining-page-title/ Share on other sites More sharing options...
fert Posted March 22, 2007 Share Posted March 22, 2007 your host has disabled allow_url_fopen and th only other way that I know of to get the contents of a page is with cURL Quote Link to comment https://forums.phpfreaks.com/topic/43773-obtaining-page-title/#findComment-212520 Share on other sites More sharing options...
Maverickb7 Posted March 22, 2007 Author Share Posted March 22, 2007 How would I go about doing that? I did a quick google search and haven't been able to find any examples that would push me in the right direction. Quote Link to comment https://forums.phpfreaks.com/topic/43773-obtaining-page-title/#findComment-212521 Share on other sites More sharing options...
fert Posted March 22, 2007 Share Posted March 22, 2007 There are plenty of examples on the php site: http://us3.php.net/manual/en/ref.curl.php Quote Link to comment https://forums.phpfreaks.com/topic/43773-obtaining-page-title/#findComment-212527 Share on other sites More sharing options...
Maverickb7 Posted March 22, 2007 Author Share Posted March 22, 2007 Alright. I understand they have lots of examples but I don't see anything that shows me how to obtain the page title. The word "title" doesn't even show up on that page. Quote Link to comment https://forums.phpfreaks.com/topic/43773-obtaining-page-title/#findComment-212530 Share on other sites More sharing options...
fert Posted March 22, 2007 Share Posted March 22, 2007 to extract the title you'll need to use Regex to parse the info out. Quote Link to comment https://forums.phpfreaks.com/topic/43773-obtaining-page-title/#findComment-212540 Share on other sites More sharing options...
Maverickb7 Posted March 22, 2007 Author Share Posted March 22, 2007 Alright i'm trying to get my host to enable url_fopen but until then I still have to find a work around. I'm searching for these terms on google and I'm not coming up with many helpful examples. What would I search for using google? Sorry if I'm coming off as a n00b, just trying to get my head in this stuff. Quote Link to comment https://forums.phpfreaks.com/topic/43773-obtaining-page-title/#findComment-212556 Share on other sites More sharing options...
jitesh Posted March 22, 2007 Share Posted March 22, 2007 I have write a scripts Test it <?php ob_start(); readfile('http://www.yahoo.com'); $con = ob_get_clean(); $filecontents = htmlentities($con); echo substr($filecontents,strpos($filecontents,"<title>")+13,(strpos($filecontents,"</title>")-strpos($filecontents,"<title>")-13)); ?> Quote Link to comment https://forums.phpfreaks.com/topic/43773-obtaining-page-title/#findComment-212581 Share on other sites More sharing options...
Maverickb7 Posted March 22, 2007 Author Share Posted March 22, 2007 I'll give your code a try. I actually coded something already using CURL like the above user suggested. After doing some research I managed to put together some code that works PERFECt. Thanks everyone! Quote Link to comment https://forums.phpfreaks.com/topic/43773-obtaining-page-title/#findComment-212583 Share on other sites More sharing options...
jitesh Posted March 22, 2007 Share Posted March 22, 2007 <?php ob_start(); readfile('http://www.yahoo.com'); $con = ob_get_clean(); $filecontents = strtolower(htmlentities($con)); echo substr($filecontents,strpos($filecontents,"<title>")+13,(strpos($filecontents,"</title>")-strpos($filecontents,"<title>")-13)); ?> Quote Link to comment https://forums.phpfreaks.com/topic/43773-obtaining-page-title/#findComment-212720 Share on other sites More sharing options...
jitesh Posted March 22, 2007 Share Posted March 22, 2007 // For Greter version of PHP function get_string_between($string, $start, $end){ $string = " ".$string; $ini = strripos($string,$start); if ($ini == 0) return ""; $ini += strlen($start); $len = strripos($string,$end,$ini) - $ini; return substr($string,$ini,$len); } ob_start(); readfile('http://www.rediff.com'); $con = ob_get_clean(); $filecontents = htmlentities($con); echo get_string_between($filecontents,"<title>","</title>"); Quote Link to comment https://forums.phpfreaks.com/topic/43773-obtaining-page-title/#findComment-212739 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.