public static function handleImages($html) { $simpleDom = new \SimpleHTMLDOM(); $html = $simpleDom->str_get_html($html); foreach ($html->find('image') as $image) { } $html->load($html->save()); return $html; }
/** * HTML Format * * @param $data */ public function postProcessing(&$data) { \Yii::import('ext.SimpleHTMLDOM.SimpleHTMLDOM'); //\Yii::log(print_r($data, true), 'info', 'api'); /**@todo: clear*/ for ($i = 0; $i < count($data); $i++) { $simpleDom = new \SimpleHTMLDOM(); $html = $simpleDom->str_get_html($data[$i]['html']); foreach ($html->find('img') as $smile) { $smile->outertext = '<smile>' . $smile->src . '</smile>'; } $html->load($html->save()); foreach ($html->find('iframe') as $video) { $video->outertext = '<video>' . $video->src . '</video>'; } $html->load($html->save()); foreach ($html->find('picture') as $picture) { $picture->outertext = '<image>' . $picture->first_child()->srcset . '</image>'; } $html->load($html->save()); /*foreach ($html->find('a') as $link) { $link->outertext = '<link><src>' . $link->href . '</src><title>' . $link->innertext . '</title></link>'; } $html->load($html->save());*/ foreach ($html->find('comment') as $comment) { $comment->outertext = ''; } $html->load($html->save()); foreach ($html->find('photo-collection') as $collection) { $data[$i]['photo-collection'] = $collection->params; $collection->outertext = ''; } $html->load($html->save()); $this->clearTags($html, 'div[class=b-article_in-img]'); /*$tags = array('div', 'strong', 'del', 'em', 'b', 'u', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6',); foreach ($tags as $key => $tag) { $this->clearTags($html, $tag); //\Yii::log((string)$html, 'info', 'api'); }*/ //\Yii::log(print_r($html->nodes, true), 'info', 'api'); $html->load($html->save()); $data[$i]['html'] = $html->outertext; } }