I want a preg_match code that will detect a given string and get its wrapping element. I have a string and a html code like:
$string = \"My text\";
$html = \"<
Even if regex is never the correct answer in the domain of dom parsing, I came out with another (quite simple) solution
<[^>/]+?>My String
if the html is good (ie it has closing tags, < is replaced with < & so on). This way you have in the first regex group the opening tag and in the second the closing one.