The Little Guy Posted February 25, 2010 Share Posted February 25, 2010 I am trying to get the title tag from a html string. I have this: if(preg_match("~\<title.+?\>(.+?)\</title\>~i", $this->info, $matches)){ return $matches[1]; } but it only works on sites where the title looks something like this <title id="something">Title Here</title> but when it looks like this: <title>Title Here</title> it doesn't work. What can I do? Quote Link to comment https://forums.phpfreaks.com/topic/193397-get-title-tag/ Share on other sites More sharing options...
Adam Posted February 25, 2010 Share Posted February 25, 2010 Change the regexp to: ~\<title.*?>(.+?)\</title\>~i Quote Link to comment https://forums.phpfreaks.com/topic/193397-get-title-tag/#findComment-1018226 Share on other sites More sharing options...
The Little Guy Posted February 27, 2010 Author Share Posted February 27, 2010 Thanks that worked! Sorry it took so long I forgot about this thread Quote Link to comment https://forums.phpfreaks.com/topic/193397-get-title-tag/#findComment-1018846 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.