# Sửa lỗi Simple html dom file\_get\_html not working - is there any workaround? (ok)

Đã ok

```
<?php
include('simple_html_dom.php');
// Report all PHP errors (see changelog)
$base = 'https://mediamart.vn';

$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_URL, $base);
curl_setopt($curl, CURLOPT_REFERER, $base);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$str = curl_exec($curl);
curl_close($curl);

// Create a DOM object
$html_base = new simple_html_dom();
// Load HTML from a string
$html_base->load($str);

//get all category links
foreach($html_base->find('a') as $element) {
    echo "<pre>";
    print_r( $element->href );
    echo "</pre>";
}

$html_base->clear(); 
unset($html_base);

?>
```

98

```
<?php
// Report all PHP errors (see changelog)
error_reporting(E_ALL);

include('inc/simple_html_dom.php');

    //base url
    $base = 'https://play.google.com/store/apps';

    //home page HTML
    $html_base = file_get_html( $base );

    //get all category links
    foreach($html_base->find('a') as $element) {
        echo "<pre>";
        print_r( $element->href );
        echo "</pre>";
    }

    $html_base->clear(); 
    unset($html_base);

?>
```

I have the above code and I'm trying to get certain elements of the Play Store page but it isn't returning anything. Is it possible that certain PHP functions might be disabled on the server to stop that?

The above code works perfectly on other sites.

Is there any workaround?[php](https://stackoverflow.com/questions/tagged/php) [html-parsing](https://stackoverflow.com/questions/tagged/html-parsing) [file-get-contents](https://stackoverflow.com/questions/tagged/file-get-contents) [simple-html-dom](https://stackoverflow.com/questions/tagged/simple-html-dom)[share](https://stackoverflow.com/q/18667441)  [improve this question](https://stackoverflow.com/posts/18667441/edit)  follow [edited Mar 31 '14 at 23:45](https://stackoverflow.com/posts/18667441/revisions)[![](https://www.gravatar.com/avatar/a86a311e34d94a802e8bf88e2807ede3?s=32\&d=identicon\&r=PG)](https://stackoverflow.com/users/64046/jasonmarcher)[JasonMArcher](https://stackoverflow.com/users/64046/jasonmarcher)11.2k1111 gold badges5151 silver badges5050 bronze badgesasked Sep 6 '13 at 22:20[![](https://i.stack.imgur.com/Cfvvn.jpg?s=32\&g=1)](https://stackoverflow.com/users/890844/altin)[Altin](https://stackoverflow.com/users/890844/altin)1,41522 gold badges2020 silver badges4242 bronze badges

* Working fine for me tho... – [Enissay](https://stackoverflow.com/users/1519058/enissay) [Sep 7 '13 at 0:35](https://stackoverflow.com/questions/18667441/simple-html-dom-file-get-html-not-working-is-there-any-workaround#comment27494443_18667441)

[add a comment](https://stackoverflow.com/questions/18667441/simple-html-dom-file-get-html-not-working-is-there-any-workaround)

### 4 Answers

[Active](https://stackoverflow.com/questions/18667441/simple-html-dom-file-get-html-not-working-is-there-any-workaround?answertab=active#tab-top)[Oldest](https://stackoverflow.com/questions/18667441/simple-html-dom-file-get-html-not-working-is-there-any-workaround?answertab=oldest#tab-top)[Votes](https://stackoverflow.com/questions/18667441/simple-html-dom-file-get-html-not-working-is-there-any-workaround?answertab=votes#tab-top)35

As I said, your example is working fine for me... But try this way using curl instead:

```
//base url
$base = 'https://play.google.com/store/apps';

$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_URL, $base);
curl_setopt($curl, CURLOPT_REFERER, $base);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$str = curl_exec($curl);
curl_close($curl);

// Create a DOM object
$html_base = new simple_html_dom();
// Load HTML from a string
$html_base->load($str);

//get all category links
foreach($html_base->find('a') as $element) {
    echo "<pre>";
    print_r( $element->href );
    echo "</pre>";
}

$html_base->clear(); 
unset($html_base);
```

It gets all the links as expected:

![enter image description here](https://i.stack.imgur.com/2NRhV.png)

And make sure you have `php_openssl` and `php_curl` installed...[share](https://stackoverflow.com/a/18668562)  [improve this answer](https://stackoverflow.com/posts/18668562/edit)  follow answered Sep 7 '13 at 0:45[![](https://www.gravatar.com/avatar/c4c40c72d7fee8c91b13e1b4c2ad1458?s=32\&d=identicon\&r=PG)](https://stackoverflow.com/users/1519058/enissay)[Enissay](https://stackoverflow.com/users/1519058/enissay)4,64733 gold badges2424 silver badges4747 bronze badges

* 1wow thank you, as you said, I just needed to activate the "php\_openssl" extension and it works now :) I'm using WAMP Server on windows and it was inactive by default. Thanks man! – [Altin](https://stackoverflow.com/users/890844/altin) [Sep 7 '13 at 3:19](https://stackoverflow.com/questions/18667441/simple-html-dom-file-get-html-not-working-is-there-any-workaround#comment27495839_18668562)

[add a comment](https://stackoverflow.com/questions/18667441/simple-html-dom-file-get-html-not-working-is-there-any-workaround)3

remove the semicolon from php.ini and restart Apache server to enable php module configuration

```
; Windows Extensions
...
;extension=php_openssl.dll
...
```

[share](https://stackoverflow.com/a/39091241)  [improve this answer](https://stackoverflow.com/posts/39091241/edit)  follow answered Aug 23 '16 at 2:05[![](https://www.gravatar.com/avatar/3510a78133744a0b7f3c5318a1ff7f46?s=32\&d=identicon\&r=PG\&f=1)](https://stackoverflow.com/users/6745840/chitsai-yeh)[Chitsai Yeh](https://stackoverflow.com/users/6745840/chitsai-yeh)4611 bronze badge[add a comment](https://stackoverflow.com/questions/18667441/simple-html-dom-file-get-html-not-working-is-there-any-workaround)2

You must set "allow\_url\_fopen" as TRUE in "php.ini" to allow accessing files via HTTP or FTP.\
Some hosting venders disable PHP's "allow\_url\_fopen" flag for security issues.[share](https://stackoverflow.com/a/27830233)  [improve this answer](https://stackoverflow.com/posts/27830233/edit)  follow answered Jan 7 '15 at 23:01[![](https://www.gravatar.com/avatar/c8bb4913ac9ac390cad92d85fec2ff9a?s=32\&d=identicon\&r=PG)](https://stackoverflow.com/users/500446/shahil)[shahil](https://stackoverflow.com/users/500446/shahil)72377 silver badges1717 bronze badges[add a comment](https://stackoverflow.com/questions/18667441/simple-html-dom-file-get-html-not-working-is-there-any-workaround)1

```
$post = curl_init(); 
curl_setopt($post, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($post, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($post, CURLOPT_HEADER, 0);
curl_setopt($post,CURLOPT_RETURNTRANSFER, true);
curl_setopt($post,CURLOPT_URL,$website);
curl_setopt($post,CURLOPT_POST,1);
curl_setopt($post,CURLOPT_POSTFIELDS,"regno=$Number");
curl_setopt($post, CURLOPT_FOLLOWLOCATION, True);
curl_getinfo($post, CURLINFO_HTTP_CODE);
$curlresponse = curl_exec($post);
curl_close($post);  
$dom = new DOMDocument();
$dom->loadHTML($curlresponse);
```

DOMDocument::loadHTML() \[domdocument.loadhtml]: htmlParseStartTag: misplaced THIS IS URL : <http://www.annauniv.edu/cgi-bin/result/cgrade.pl?regno=11210104001>
