Solved

Extract Body from HTML Page (PHP)

Posted on 2009-05-17
2
952 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
2 Comments
 
LVL 18

Accepted Solution

by:
Hube02 earned 500 total points
Comment Utility
Give this a try:


$regex = '/<body[^>]*>/i';
 

preg_match($regex, $page_content, $matches);
 

echo $matches[0];

Open in new window

0
 
LVL 34

Expert Comment

by:gr8gonzo
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

771 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now