Solved

Extract Body from HTML Page (PHP)

Posted on 2009-05-17
2
980 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 500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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.
The viewer will learn how to dynamically set the form action using jQuery.
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…

739 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