Open Open - 4 months ago 12
PHP Question

& symbol in title breaking variable

Currently I am trying to make it so that if my title contains

&
in the title it will pass through the url below.

dl.php?&u='.$mp3.'&n='.$auth2.'


Currently I have the following code

$auth = urlencode($title2);
$auth2 = urldecode($auth);
$title2 = 'Artist - Song Name (Feat. Another Artist & Last Artist)';


You can see below that the
$title2
portion contains an
&
symbol, if this passes through our URL the download will look like this
Artist - Song Name (Feat. Another Artist)
leaving out the last artist in the MP3's name.

Any help is gratefully appreciated.

Answer

You need to fix the URL first so you can parse it correctly later on. Use http_build_query: http://php.net/http_build_query, it will urlencode things correctly for you

'dl.php?' . http_build_query(array('u' => $mp3, 'n' => $auth2));