"meltedown" <fa**@fake.net> wrote in message
news:Ec***********************@news.easynews.com.. .
I want to match a table and also capture the parts before and after the
table:
preg_match_all("|(.*)(<table.*table>)(.*)|",$text, $parts);
But of course it doesn't work, presumably because the first .* is
greedy. I tried adding an ? but that doesn't work either. How do I do
this ?
You might be confused at the results because they contain the table HTML.
But you were right first time.
$text="|before<table>stuff goes here</table>after|";
print htmlspecialchars($text)."<br>";
preg_match_all("|(.*?)(<table.*table>)(.*)|",$text , $parts);
print("Before: ".$parts[1][0]);
print "<br>Inner: ";
print htmlspecialchars($parts[2][0]);
print "<br>";
print("After: ".$parts[3][0]);
Results:
|before<table>stuff goes here</table>after|
Before: |before
Inner: <table>stuff goes here</table>
After: after|
Isn't this what you wanted?
HTH
Garp