Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Getting first image from content.


Go to End


2 Posts   567 Views

Avatar
steveazz

Community Member, 1 Post

17 July 2015 at 12:42am

I have the following method where it is suppose to get the first image that is displayed from the content.

public function FirstImage($content)
{
$dom = new DOMDocument();
$dom->loadHTML($content);

Debug::dump($content);

}
The wierd thing is when i do $dom->loadHTML I get the following error Empty string supplied as input, but as soon as I dump it I do get the correct data. How can I fix this problem ?

I also done $this->owner->Content which has the same thing.

Avatar
Pyromanik

Community Member, 419 Posts

18 July 2015 at 12:00am

You've provided no context to your function.
If $content is an empty string, then it's because you've passed an empty string as the parameter.

You've also not provided any context as to how it's called. Is this a controller function or something applied via Extension?

I cannot help you with this.