vesper Posted September 15, 2008 Share Posted September 15, 2008 Hi there, I've got a piece of code that let's me obtain the title of a page using a given URL. However, if the title tag has any other code in it, for example <title id="something">, it does not work because the preg_match is looking for just the open and closing tags. My question is: how can I get the code to ignore anything between '<title' and '>'?? The preg_match currently looks like this: preg_match("/<title>(.+)<\/title>/i",$file,$m) Thanks. Quote Link to comment Share on other sites More sharing options...
metrostars Posted September 15, 2008 Share Posted September 15, 2008 I'm not very good at regex. In fact I hate it. but try (untested): preg_match("/<title([.]{0,})>(.+)<\/title>/i",$file,$m) This will match <title 'then anything in here' >Blah</title> Quote Link to comment Share on other sites More sharing options...
vesper Posted September 15, 2008 Author Share Posted September 15, 2008 Hi metrostars, I just tried it, unfortunately it didn't work. Thanks for the reply though. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted September 15, 2008 Share Posted September 15, 2008 Try this one out: preg_match("/<title.*?>(.*?)<\/title>/i", $file, $m); Quote Link to comment Share on other sites More sharing options...
vesper Posted September 15, 2008 Author Share Posted September 15, 2008 It worked! Superb! Thanks for that! Hugely appreciated - headache seeping away now! Quote Link to comment 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.