1

I haven't used DOMdocument before so the syntax etc is all a bit new to me.

I'm trying to use PHP DOMdocument and Xpath to find and element by a specific class name and then wrap it in a new tag.

Eg: I have this inside a <content:encoded> block:

<iframe class="youtubeEmbed figureWrap" src="..."></iframe>

The class figureWrap means it needs wrapping in <figure> tags and youtubeEmbed means that figure requires a specific class adding to it (op-interactive)

I've found xpath query to detect things by class name but beyond that I'm getting a bit stuck. Can anyone help?

MrLewk
  • 498
  • 1
  • 6
  • 24
  • 1
    `class` attributes are a little tricky, because they can contain several class names. I explained it here: http://stackoverflow.com/a/33446305/2265374 – ThW Feb 09 '17 at 08:54
  • @ThW thanks I've got it to wrap now, but ideally I'd be good to remove (or change?) the parent

    tag into the new wrapper element if that's feasible?

    – MrLewk Feb 10 '17 at 08:02
  • Changing node name, type or namespace is not possible. Create a new node, insert it before the one you want to replace, append all children to the new node and remove the old. – ThW Feb 10 '17 at 08:26
  • @ThW that's what I suspected I needed to do. I'm just having trouble getting the parent. Using the code in the main question, I've got that iframe but it's wrapped in

    tags. I use xpath the find it and wrap in a

    tag, but still need to remove the parent paragraph wrapper. That's where I get stuck

    – MrLewk Feb 10 '17 at 08:31

0 Answers0