yahn Posted July 8, 2007 Share Posted July 8, 2007 I want to find the beginning of html, head and body tags. I'm using /<?/html|/<?/head/|/<?/body/ what am I doing wrong? I'm not very good with regex, so probably a lot, but if someone could help me out I would really appreciate it. Thank you. Quote Link to comment Share on other sites More sharing options...
Yesideez Posted July 8, 2007 Share Posted July 8, 2007 I'll have a crack, just started learning regex myself! <(html|head|body) I think that will match anything starting in <html, <head or <body Quote Link to comment Share on other sites More sharing options...
Wildbug Posted July 8, 2007 Share Posted July 8, 2007 What do you mean you want to find the beginning? Do you just want to verify the tags, or do you want some content, too? <?php // To simply verify tags, you can use: preg_match_all('/<(?:html|head|body)[^>]*>/i',$html,$matches); // To capture the opening tags, use: preg_match_all('/(<(?:html|head|body)[^>]*>)/i',$html,$matches); // To capture the opening tag, closing tag, and everything in between: preg_match_all('/<(html|head|body)[^>]*>(.*?)<\/\1>/i',$html,$matches); ?> You can use the PREG_OFFSET_CAPTURE flag to find where the offset is. Quote Link to comment Share on other sites More sharing options...
yahn Posted July 8, 2007 Author Share Posted July 8, 2007 I just want to find the tag itself. I want to be able to find <body and </body. it is finding <body but it's not finding </body. My regex now is: /(<(?:html|head|body)[^>]*>)/i . Is there anything wrong? Quote Link to comment Share on other sites More sharing options...
Wildbug Posted July 9, 2007 Share Posted July 9, 2007 You can use this to match beginning and end tags: /<\/?(?:html|head|body).*?>/is 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.