Search code examples
phpsimple-html-dom

What's the difference between file_get_contents a variable and a string?


I have source code :

A.

$this->eArticle["product_link"] = 'http://afamily.vn/doi-song/lop-hoc-toa-tau-day-nham-mat-ve-obama-khien-tre-thich-me-20150530074455878.chn';
print file_get_contents($this->eArticle["product_link"]);

AND

B.

print file_get_contents('http://afamily.vn/doi-song/lop-hoc-toa-tau-day-nham-mat-ve-obama-khien-tre-thich-me-20150530074455878.chn');

In A, result return NULL ( screen haven't text )

In B, result display website http://afamily.vn/doi-song/lop-hoc-toa-tau-day-nham-mat-ve-obama-khien-tre-thich-me-20150530074455878.chn

Why ? How fix ? Thanks !


Solution

  • I am nt quite sure about what you did but

    you can try storing it in a variable and function is file_get_contents() and not file_get_content(), NOTE for the "s" that you have missed

    $this->eArticle["product_link"] = 'http://afamily.vn/doi-song/lop-hoc-toa-tau-day-nham-mat-ve-obama-khien-tre-thich-me-20150530074455878.chn';
    
    $website_link = trim($this->eArticle["product_link"]);
    
    echo file_get_contents($website_link);
    

    Check out the Docs