[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

PHP Multi Line preg_replace problem

Posted on 2007-10-03
1
Medium Priority
?
3,297 Views
Last Modified: 2013-12-13
I am attempting to trim the starting html tags from an html file.  A shortened version of the  original file looks like this:

==============================================================

<HTML>
<HEAD>
<TITLE>Team Manager Individual Meet Results by Name</TITLE>
</HEAD>
<BODY>
<TABLE ALIGN=BLEEDLEFT WIDTH=100% CELLSPACING=0 CELLPADDING=0 BORDER=0>
<TR>
<TD WIDTH=1.053%></TD>
<TD WIDTH=1.053%></TD>
<TD WIDTH=1.053%></TD>
<TD WIDTH=1.053%></TD>
<TD WIDTH=2.105%></TD>
</TR>
</TABLE>
</BODY>
</HTML>
==============================================================

I need to remove the:

<HTML>
<HEAD>
<TITLE>Team Manager Individual Meet Results by Name</TITLE>
</HEAD>
<BODY>

and

</BODY>
</HTML>

using php's preg_replace function.  I cannot use str_replace, at least at the top, because what is between the TITLE tags may change.

I have tried  $meet_result=preg_replace("/<HTML>.*(^[<BODY>]$)/i","",$meet_result); (where $meet_result is the code above) to remove everything before the opening table tag, but this does not work.

Any ideas?
0
Comment
Question by:alanpollenz
1 Comment
 
LVL 48

Accepted Solution

by:
hernst42 earned 2000 total points
ID: 20005635
You can use preg:match to get the text between the body tags:

$m = array();
preg_match('/<body[^>]*>(.*)<\/body>/is', $html, $m);
echo $m[1];
0

Featured Post

Independent Software Vendors: 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

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…
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.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses
Course of the Month18 days, 10 hours left to enroll

834 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