Using the following code I get "img" tags from some html and check them if they are covered with "a" tags. Later if current "img" tag is not part of the "a" ( hyperlink ) I want to do cover this img tag into "a" tag adding hyperlinks start ending tag plus setting to target. For this I want the whole "img" tags html to work with.
Question is how can I transfer "img" tags html into regexp. I need some php variable in regexp to work with the place is marked with ??? signs.
$doc = new DOMDocument();
$doc->loadHTML($article_header);
$imgs = $doc->getElementsByTagName('img');
foreach ($imgs as $img) {
if ($img->parentNode->tagName != "a") {
preg_match_all("|<img(.*)\/>|U", ??? , $matches, PREG_PATTERN_ORDER);
}
}