I have a string let's say "John doe", I'm trying to figure out what HTML tag that contains that word.
I have a dom as a string and trying to match what tag contains that word. In this case, a span tag with class full-name
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
<span class="full-name">John doe</span>
</body>
</html>
My code looks something like this so far, but do not get it to work, it just gets the entire DOM before the word
preg_match('/<(.*?)'.$name.'/s', $html, $match);
$matchBefore = $match[0];
preg_match('/'.$name.'(.*?)>/s', $html, $match);
$matchAfter = $match[0];
question from:
https://stackoverflow.com/questions/66061310/get-html-tag-containing-string 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…