Need help, find BODY tag and values (Pattern matching)

$URL_GRAB = "<body onclick='asdsd asd> ' asd> asd </body>";

<textarea name="result" rows="30" cols="80">
<?php
if (preg_match_all("/^<body.*?|>.*?<\/body>$/i", $URL_GRAB, $matches))
{
print_r($matches);
}
else
{
print_r('none');
}
}
?>
</textarea>


closes *result* i could get is

Array
(
    [0] => Array
        (
            [0] => <body
            [1] => > \' asd> asd </body>
        )

)


How do i make it
Array
(
    [0] => Array
        (
            [0] => <body onclick='asdsd asd> ' asd>
            [1] => asd
            [2] => </body>
        )

)

i am having trouble getting my pattern matching right
this pattern "/^<body.*?|>.*?<\/body>$/i" is lacking..


i want a pattern that
starts with
(
      starts with <body
      zero or more
      (zero or more [a-zA-Z]characters
            (' and matching ending tag ' | " and matching ending tag " )
      )
      ends with >
)
followed by any characters
ends with </body>

help.. going nuts with pattern matching. i tried different pattern matching but it doesnt work, this is the closiest i could get.
LVL 9
Jerry_PangAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pvginkelCommented:
I'm not really clear what you want, but this will make the regexp working:

/<body.*>(.*)<\/body>/isU
RoonaanCommented:
if (preg_match_all("#<body[^>]*>(.*)</body>#/ims", $URL_GRAB, $matches))

-r-
thyminfoCommented:
Hi!
If your ' $URL_GRAB' value is typed in correctly and if you are looking for result to be
Array
(
    [0] => Array
        (
            [0] => <body onclick='asdsd asd> ' asd>
            [1] => asd
            [2] => </body>
        )

)

you should use the following:

if (preg_match_all("/^(<body[^<]*>)(.*)(</body>)$/i", $URL_GRAB, $matches))

-Cheers!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jerry_PangAuthor Commented:
hi.. what does the following mean?
[^>]
/m
/s

the most important element that i need is only the  [1] => asd
only what is inside the <body> tag.

i just realize its kinda like xml. but i only need whats inside it.
i tried it on real example like the following..

pvginkel, Roonaan  the array [1] is correct. i was wondering why there is no <\/body> in any results.
Array
(
    [0] => <body bgcolor=\"#FFFFFF\" leftmargin=\"0\" topmargin=\"0\" marginwidth=\"0\" marginheight=\"0\" vlink=\"#666666\" text=\"#000000\">
<basefont size=\"3\">
<!-- BEGIN NO PRINT -->
</body>
    [1] =>
<basefont size=\"3\">
<!-- BEGIN NO PRINT -->

)



thyminfo, it does now work on the above example. but i added the Roonaan's #/ims, and it works fine.
Jerry_PangAuthor Commented:
"/^(<body[^<]*>)(.*)(<\/body>)$/ims"
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.