I have a script which gets the inside of a body tag but not the outside, and I require both. I've searched around and I can only find code to get the inside of the body tag, not the outside. Any help? I could explode the string with "body" but the problem is, the attributes of the body tag can change and that's what I'm stumped on -_-
Asked
Active
Viewed 234 times
0
-
8regexes on html? this is madness! Use [DOM](http://php.net/dom) instead. – Marc B Aug 02 '12 at 15:32
-
4[Here's an SO article on why regex is a bad idea for HTML parsing.](http://stackoverflow.com/questions/590747/using-regular-expressions-to-parse-html-why-not) – Matt Aug 02 '12 at 15:33
-
2@Matt: You might have linked http://stackoverflow.com/a/1732454/135078, to back MarcB's statement :-) – Bergi Aug 02 '12 at 15:41
-
@Bergi +1 for finding more ammo. – Matt Aug 02 '12 at 15:42
1 Answers
0
if you really want to use Regex to search outside of the <body>...</body>
, try with this(PHP):
/<body[^>]*+>([^<]*+(?:(?!<\/?+body)<[^<]*+)*+)<\/body>/
and keep start and end position from search result, use these for search outside of body tag.

godspeedlee
- 672
- 3
- 7