physaux Posted November 2, 2009 Share Posted November 2, 2009 hey guys, I have a quick question again. How can I retrieve JUST <title>THIS TEXT</title> from a URL, using php? I would open the file, or do a HTTP request, then search for the string with regex, but that would be really inefficient because I only want the title data. Thanks in advance!! Link to comment https://forums.phpfreaks.com/topic/180005-solved-retrieving-data-from-another-urls-title/ Share on other sites More sharing options...
Jnerocorp Posted November 2, 2009 Share Posted November 2, 2009 do you mean something like this? the url: http://domain.com/index.php?title=THIS%20TEXT the code: <html> <head> <?php if(isset($_GET['title'])) { $title = $_GET['title']; ?> <title><?php echo $title; ?></title> <?php } else { ?> <title> Title Not set </title> <?php } ?> </head> <body> </body> </html> Link to comment https://forums.phpfreaks.com/topic/180005-solved-retrieving-data-from-another-urls-title/#findComment-949635 Share on other sites More sharing options...
physaux Posted November 2, 2009 Author Share Posted November 2, 2009 Thanks, but that's not what I meant I should have specified I wanted the text between the <titile> tags in the HTML source code But i got it solved now, I just did it the long way. Thanks anyway! Link to comment https://forums.phpfreaks.com/topic/180005-solved-retrieving-data-from-another-urls-title/#findComment-949642 Share on other sites More sharing options...
Andy-H Posted November 2, 2009 Share Posted November 2, 2009 <?php $url = '[url=http://www.test.com]http://www.test.com[/url]'; $markUp = file_get_contents($url); if ( preg_match('#<title>(.*)</title>#i', $markUp, $matches) != false) $title = strip_tags($matches[0]); echo $title; ?> Worst regex pattern going probably, but it's my first lol Link to comment https://forums.phpfreaks.com/topic/180005-solved-retrieving-data-from-another-urls-title/#findComment-949651 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.