redeclare file_get_html simple_html_dom.php

php, simple-html-dom, simpledom

Solution

Change your `include` to `include_once`. This is because you are including the same file twice - and each time you include it, you are declaring the `file_get_html` function.

Edit: You probably want to do the same with your `require` on the following line, changing it to `require_once`

Problem

I am using simple html dom to parse itunes preview page When I put URL in code [download]url[/download] once everything okey, but when I have 2 or more [download]url[/download] codes I getting an error Fatal error: Cannot redeclare file_get_html() (previously declared in /var/.../simple_html_dom.php:65) in /var/.../simple_html_dom.php on line 80 ``` function download_link($link){ $file=ROOT_DIR."/engine/data/obmennik.php"; include '/var/.../simple_html_dom.php'; //ПАРСИНГ require($file); $site=parse_url($link); $domain=$site['host']; $itunes = file_get_html($link); //ПАРС $image = $itunes->find('img.artwork[width=175]',0); //ПАРС $e = $itunes->find("div.price", 0); $u = $itunes->find("h1", 0); $star = $itunes->find("div.rating", 0); $un = $itunes->find("div.fat-binary-blurb", 0); $dt=date('Y-m-d [H:00]'); if(array_key_exists($domain,$link_arr)){ $link="\n".'<br><a title="Скачать файл c '.$domain.'" rel="nofollow" target="_blank" href="http://li.ru/go?'.$link.'"><div style="-webkit-border-radius: 8px;-moz-border-radius: 8px;border-radius: 8px;background: #DCDCDC;"><table><tr><td width="35%"><img class="its_small" src=\"'.$image->src.'\" /></td><td width="65%" valign="middle" align="center"><span style="font-size:16px; font-weight: bold;"> '.iconv("UTF-8","cp1251",$u->plaintext). '<br> [iTunes Link, '.iconv("UTF-8","cp1251",$e->plaintext).']</span><br><br>'.iconv("UTF-8","cp1251",$un->outertext).'<br>Рейтинг на: '.$dt.' '.$star->outertext.'</td></tr></table></div></a>'; } return $link; } function decode_base64($code){ $code="[download]".trim(base64_decode($code))."[/download]"; return $code; $itunes->clear(); } ```

Original source