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


$song = $_GET['song']);

$url = "http://www.lyrdb.com/lookup.php?for=fullt&q=";

echo "list url is " . htmlentities($url . $song) . "<hr>";

$content = file_get_contents($url . urlencode($song));

echo $content;

      



+12


source


$data = json_encode($_POST);

$url = "http://www.index.com?data=";

echo file_get_contents($url . urlencode($data));

      



0


source







All Articles