Hi all
I want to use the php function preg_match_all to find a part of the html code to replace it by another one.
This is what I need to find:
<attachfiles>
tag{link} attr{rel="stylesheet" type="text/css" media="screen"}
sources{
file1.css,
file2.css
}
</attachfiles>
I made a regular expression that find it but only if that code is present once into the entire html.
My regular expression is:
"|\<attachfiles\>(.*)\<\/attachfiles\>|s"
The issue comes out when I have the code to find repeated two or more times. Since the regular expression uses the |s operator (multiline), when I have the code more than one time it returns all the html code from the very first to the vary last
For example:
<attachfiles>
tag{link} attr{rel="stylesheet" type="text/css" media="screen"}
sources{
file1.css,
file2.css
}
</attachfiles>
... html code ...
... html code ...
<attachfiles>
tag{script} attr{type="text/css" language="javascript"}
sources{
file1.js,
file2.js
}
</attachfiles>
My regular expression in this case is returning ALL the code, from the first
<attachfiles> to the last </attachfiles>
including the
... html code ...
... html code ...
that is between the code that I am searching for.
Anyone knows how to solve it???
Thanks in advance
Ivano