Reputation: 87
I have a url like this, https://www.example.com/send?id=1
&text=http://example2.com/song.mp3
when I try to get the data of the url using file_get_contents()
it shows below error,
PHP Warning: file_get_contents(https://www.example.com/send?id=1
&text=http://example2.com/song.mp3
):
failed to open stream: HTTP request failed! HTTP/1.1 501 Not Implemented
and the & have converted to &. due to that the url is not working.
I have tried htmlspecialchars_decode()
and preg_replace()
on & , but it didn't do anything.
how to solve this ?
Upvotes: 1
Views: 2640
Reputation: 65
take a look at this sir, where $str="your link"
sample
$str = "https://www.example.com/send?id=1&text=http://example2.com/song.mp3";
echo html_entity_decode($str);
will output the one you want....
Upvotes: 1
Reputation: 481
I think you better to use cURL
instead of file_get_contents()
, because referring server must be enabled allow_url_fopen
in their server if you are using file_get_contents()
, but cURL is a library it just make a http requests
<?php
$cSession = curl_init();
curl_setopt($cSession,CURLOPT_URL,"https://www.example.com/send?id=1&text=http://example2.com/song.mp3");
curl_setopt($cSession,CURLOPT_RETURNTRANSFER,true);
curl_setopt($cSession,CURLOPT_HEADER, false);
$result=curl_exec($cSession);
curl_close($cSession);
echo $result;
?>
refer following links
file_get_contents script works with some websites but not others
Upvotes: 1