Solved

Extract Body from HTML Page (PHP)

Posted on 2009-05-17
2
970 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
ID: 24408618
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
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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 look for a specific file type in a local or remote server directory using PHP.

789 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