0

I have a string variable of contents such as:

$str = '<img src="ptah/to/image.ext"><br>some text <b>text agian</b> etc';

I need to use Xpath to evaluate the image src attribute in that string //img/@src. However, from the domXPath documentation we have to load document from a file:

$doc = new DOMDocument;
// We don't want to bother with white spaces
$doc->preserveWhiteSpace = false;
$doc->Load('book.xml');

My question is: Is there any other method than Load or any workaround to load the dom from a variable?

1 Answer 1

1

You mean something like this?

$doc->loadXML('<img src="path/to/image.ext><br>some text <b>text agian</b> etc');

If it is not standard XML input, you have to use loadHTML()

Sign up to request clarification or add additional context in comments.

1 Comment

I tried loadXML but it generated error because the string supplied is not standard XML. I bit and tried loadHTML it worked fine. Now, I'd like to know where could I find documentation for DOMDocument object's methods? Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.