File_get_contents with spaces in url
I have a problem where even if I replace the spaces with% 20 and get this content, the final url that the browser gets turns "% 20" into "% 2520"
Here is my code, any suggestions to get this to work? this seems easy, but i'm stuck: /
<?php
//$_GET['song'] will contain a song name with spaces
$song = str_replace(array("%20", "&", "?" , "/"), array(" ", "", "", ""), $_GET['song']);
// I use this to check how the GET 'song' looks after the str_replace
$list = "http://www.lyrdb.com/lookup.php?q=" . $song . "&for=fullt";
echo "list url is " . $list . "<hr>";
$content = file_get_contents("http://www.lyrdb.com/lookup.php?q=" . str_replace(" ", "%20", $song) . "&for=fullt");
echo $content;
?>
if you go to http://webservices.lyrdb.com/lookup.php?q=red%20hot%20chili%20peppers&for=fullt This should result in a list of lyric codes.
When do I visit my site /? Song = red hot chili peppers, it also converts spaces to% 20, but if it seems like the browser is converting% to% 25.
Can anyone help me?
+5
source to share
2 answers