473,395 Members | 1,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Regex with HTML in PHP

Hi,

I have the following html code and need to display all contents within the <h4> tags, except the one containing "Footer". I am writing a parser script in php to transform an old to a new html layout.

The old layout is basically like this:

<h4>Background</h4>
<h4>Advice</h4>
<h4>Footer</h4>
<h4>Support</h4>

And my regex looks like this:

$regex_newsections = "/<h4>(.*?)(?=<\/h4>)/m";

I need the brackets surrounding .*? because I will use the contents later on in the preg_match_all function.

I have tried using a negative lookahead but none of the following work:
$regex_newsections = "/<h4>(.*?)(?!Footer)(?=<\/h5>)/m";
$regex_newsections = "/<h4>((?!Footer).*?)(?=<\/h5>)/m";
$regex_newsections = "/<h4>((?!Footer)*?)(?=<\/h5>)/m";

Does anyone have any ideas? Cheers.
Feb 10 '08 #1
1 1246
ronverdonk
4,258 Expert 4TB
Hi,

I have the following html code and need to display all contents within the <h4> tags, except the one containing "Footer". I am writing a parser script in php to transform an old to a new html layout.

The old layout is basically like this:

<h4>Background</h4>
<h4>Advice</h4>
<h4>Footer</h4>
<h4>Support</h4>

And my regex looks like this:

$regex_newsections = "/<h4>(.*?)(?=<\/h4>)/m";

I need the brackets surrounding .*? because I will use the contents later on in the preg_match_all function.

I have tried using a negative lookahead but none of the following work:
$regex_newsections = "/<h4>(.*?)(?!Footer)(?=<\/h5>)/m";
$regex_newsections = "/<h4>((?!Footer).*?)(?=<\/h5>)/m";
$regex_newsections = "/<h4>((?!Footer)*?)(?=<\/h5>)/m";

Does anyone have any ideas? Cheers.
To start with the 3 instructions beginning at:
[php]
$regex_newsections = "/<h4>(.*?)(?!Footer)(?=<\/h5>)/m";
[/php]
all search for </h5> as the closing tag.

Ronald
Feb 11 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Alan Pretre | last post by:
Can anyone help me figure out a regex pattern for the following input example: xxx:a=b,c=d,yyy:e=f,zzz:www:g=h,i=j,l=m I would want four matches from this: 1. xxx a=b,c=d 2. yyy e=f 3....
1
by: kevin | last post by:
I am trying to strip the outermost html tag by capturing this tag with regex and then using the string replace function to replace it with an empty string. while stepping through the code, RegEx...
1
by: George Durzi | last post by:
Consider this excerpt from some HTML. (This is a copy from View->Source, except for the comment) <TABLE WIDTH=100% CELLPADDING=0 CELLSPACING=0 border=0> <?xml version="1.0" encoding="UTF-16"?>...
17
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher ...
7
by: Mike Labosh | last post by:
I have the following System.Text.RegularExpressions.Regex that is supposed to remove this predefined list of garbage characters from contact names that come in on import files : Dim...
5
by: Digital.Rebel.18 | last post by:
I'm trying to figure out how to extract the keywords from an HTML document. The input string would typically look like: <meta name='keywords' content='word1, more stuff, etc'> Either single...
9
by: jmchadha | last post by:
I have got the following html: "something in html ... etc.. city1... etc... <a class="font1" href="city1.html" onclick="etc."click for <b>info</bon city1 </a> ... some html. city1.. can repeat...
8
by: Xah Lee | last post by:
the Python regex documentation is available at: http://xahlee.org/perl-python/python_re-write/lib/module-re.html Note that, i've just made the terms of use clear. Also, can anyone answer what...
1
by: jonnyboy6969 | last post by:
Hi All Really hoping someone can help me out here with my deficient regex skills :) I have a function which takes a string of HTML and replaces a term (word or phrase) with a link. The pupose...
1
by: Karch | last post by:
If you run this: string result = "<html><head></head><body>The body</body></html>"; result = retainBody.Replace(result, "$1"); With the following Regex: private static readonly Regex...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.