# file_get_contents command does not work



## hiqermod (May 22, 2021)

Hello everyone, first of all, I apologize to everyone for translation errors

I started doing research to extract data from websites and found some documents and run them on my local host, then I uploaded the code to my server, but the data did not come

pkgs:
nginx-1.20.0_1,2
php80-8.0.6


my website code:

```
<?php

function getir($baslangic, $son, $cekilmek_istenen)
{
    @preg_match_all('/' . preg_quote($baslangic, '/') .
    '(.*?)'. preg_quote($son, '/').'/i', $cekilmek_istenen, $m);
    return @$m[1];
}



//Ankr Coin
$url = "https://coinmarketcap.com/currencies/ankr/";

$icerik = file_get_contents($url);

$AnkrCoin = getir('<div class="priceValue___11gHJ">','</div>',$icerik);




//Eose
$url = "https://coinmarketcap.com/currencies/eos/";

$icerik = file_get_contents($url);

$EosCoin = getir('<div class="priceValue___11gHJ">','</div>',$icerik);



//Atom
$url = "https://coinmarketcap.com/currencies/cosmos/";

$icerik = file_get_contents($url);

$CosmosAtom = getir('<div class="priceValue___11gHJ">','</div>',$icerik);




//Mkr
$url = "https://coinmarketcap.com/currencies/maker/";

$icerik = file_get_contents($url);

$Mkr = getir('<div class="priceValue___11gHJ">','</div>',$icerik);
?>

<html>

<head>
  <meta http-equiv="refresh" content="5">
</head>

<body>

  <div id="AnkCoin">
    <p>
      Ankr:<?php echo $AnkrCoin[0]; ?>
    </p>
  </div>

  <div>
    <p>
      Eos: <?php echo $EosCoin[0]; ?>
    </p>
  </div>

  <div>
    <p>
      Cosmos Atom: <?php echo $CosmosAtom[0]; ?>
    </p>
  </div>
  <div>
    <p>
      Mkr: <?php echo $Mkr[0]; ?>
    </p>
  </div>
</body>
</html>
```
thanks in advance for your help


----------



## covacat (May 23, 2021)

run phpinfo() on the 'server' and see if allow_url_fopen is on


----------



## hiqermod (May 23, 2021)

covacat said:


> run phpinfo() on the 'server' and see if allow_url_fopen is on






its on


I can see google in the expressions like this command

```
<?php
$homepage = file_get_contents('http://www.google.com/');
echo $homepage;
?>
```



but nothing happens when i change the link
for example

```
<?php
$homepage = file_get_contents('https://coinmarketcap.com/currencies/eos/');
echo $homepage;
?>
```

There is no problem when I open it using local xampp


----------



## covacat (May 23, 2021)

try to use php curl, more flexible and easier to debug


----------



## hiqermod (May 23, 2021)

covacat said:


> try to use php curl, more flexible and easier to debug


ı have php-curl extention 

I did not understand what you said


----------



## covacat (May 23, 2021)

hiqermod said:


> ı have php-curl extention
> 
> I did not understand what you said


use curl to fetch data from remote sites instead of file_get_contents


----------



## hiqermod (May 23, 2021)

covacat said:


> use curl to fetch data from remote sites instead of file_get_contents



Thanks for your suggestion, I will search


----------



## covacat (May 23, 2021)

hiqermod said:


> Thanks for your suggestion, I will search








						PHP: Examples - Manual
					






					www.php.net
				



basic example


----------

