Reputation: 518
I'm trying to get aspx url content b file_get_contents, But when I do this, the information returns inaccurately.
Html:
<head>
<meta charset="UTF-8">
</head>
Php code:
<?php
$url = "http://www.tsetmc.com/tsev2/data/instinfofast.aspx?i=65004959184388996&c=27+";
$data = file_get_contents($url);
echo $data;
?>
Upvotes: 0
Views: 194
Reputation: 2968
You screenshot look like compressed response. To get plain text, try using this:
<?php
$url = "http://www.tsetmc.com/tsev2/data/instinfofast.aspx?i=65004959184388996&c=27+";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($curl);
curl_close($curl);
echo $data;
?>
You can also use below solution but this doesn't work on all servers.
$context = stream_context_create(array(
'http'=>array(
'method' => "GET",
'header' => "Accept-Encoding: gzip;q=0, compress;q=0\r\n",
)
));
$url = "http://www.tsetmc.com/tsev2/data/instinfofast.aspx?i=65004959184388996&c=27+";
$data = file_get_contents($url, false, $contenxt);
echo $data;
I'll suggest to use cURL code because that does support on all servers.
Upvotes: 1