...
How to match the html inside(including) I need a
Here is your Regex:
preg_match('/.*<\/div>/simU', $string, $matches);
But:
- RegEx do not know what XML/HTML elements are. To them, HTML is just a string. This is why the others are right. Regex are not for parsing a DOM. They are used to find string patterns.
- I have provided the Regex because you do not intend to parse an entire HTML page, but just grab one defined piece of text from it, in which case a Regex is fine to use.
- If there is a nested DIV inside the DIV, the Regex will not work as expected. If this is the case, do not use Regex. Use one of the other solutions, because then you need DOM parsing, not string matching.
- For finding strings with a more or less clearly defined start and end, consider using regular string functions instead, as they are often quicker.