Problem Description
I have used [PHP Simple HTML DOM Parser][1] to first convert an HTML string to DOM object by `str_get_html()` method of simple_html_dom.php
$summary = str_get_html($html_string);
1. Then I extracted an `<img>` object from the `$summary` by
foreach ($summary->find('img') as $img) {
$image = $img;
break;
}
Now I needed to convert $image DOM object back to a string. I used
the [Object Oriented way mentioned here][2]:
$image_string = $image->save();
**I got the error (from the *Moodle debugger*):**
> Fatal error: Call to undefined method simple_html_dom_node::save() ...
2. So I thought since I am working with Moodle, it may have something
to do with Moodle, so I simply did the simple (non-object oriented?)
way [from the same manual][3]:
$image_string = $image;
Then just to check/confirm that it has been converted to a string, I
did:
echo '$image TYPE: '.gettype($image);
echo '<br><br>';
echo '$image_string TYPE: '.gettype($image_string);
**But this prints:**
$image TYPE: object
$image_string TYPE: object
**So the question is Why??? Am I doing something wrong?**
[1]: http://simplehtmldom.sourceforge.net/manual.htm
[2]: http://simplehtmldom.sourceforge.net/manual.htm#container_dump
[3]: http://simplehtmldom.sourceforge.net/manual.htm
AI-Generated Solution
Powered by LMSouq AI · GPT-4.1-mini
Analyzing problem and generating solution…
Was this solution helpful?