Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Extract Body from HTML Page (PHP)

Posted on 2009-05-17
2
Medium Priority
?
996 Views
Last Modified: 2012-05-07
I'm looking for a case insensitive regex to extract a body tag from a page. I want it to get return the entire opening body tag and anything in it, such as :
<body link="#000000">
<body some stuff here>
0
Comment
Question by:interclubs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 18

Accepted Solution

by:
Hube02 earned 2000 total points
ID: 24408618
Give this a try:


$regex = '/<body[^>]*>/i';
 
preg_match($regex, $page_content, $matches);
 
echo $matches[0];

Open in new window

0
 
LVL 35

Expert Comment

by:gr8gonzo
ID: 24408981
If you're going to be parsing through the contents of the body at all, you may also want to check out this:

http://simplehtmldom.sourceforge.net/

It's pretty handy and I've found it far more reliable than regexes for pattern-matching HTML elements, extracting their attributes, etc...
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question