For example in my HTML I have "img" tags. I want to pack them into "a" tags

If I do this one time everything is ok. But next time the tag which is already packed, packs again and it's bad. What I want is to understand is the "img" already packed into "a" or not.

for this I can use following...

$doc = new DOMDocument();
$doc->loadHTML($article_header);

$imgs = $doc->getElementsByTagName('img');
foreach ($imgs as $img) {

?????

}

So I will get "img" tags by this. Now How to get parent node of the "img" and check if it is "a"?

Comments

maybe get the 'a' and see if it contains an image

Written by Ibu

This thing must be working in article editor, and I have images there which must be covered with "a" tags. So I must check "img" tags first.

Written by David

please revert your edit to this question, otherwise your other question is likely to be closed as a duplicate of this one. Your question as it was before your edit received good answers, so changing it is not a good idea/recommended.

Written by Mat

You are right , I've marked 2 anwers as solutions and let's close this question cause I've started new differenet questions to continue working on this problem.

Written by David

Close them both I've strated different one. This questions are answered and are ok.

Written by David

Accepted Answer

????? would be:

if ($img->parentNode->tagName == "a") { ... }
Written by fardjad
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki