PHP str_replace not working, single qoute
my problem is frustrating, i'm taking cover art from itunes' API. This is
the code to take the song's artist and name and to retrieve the artwork:
$str = $song[0];
$artist_name = $song[0];
$posted = preg_replace('/ -.*/', '', $artist_name);
$manual_referer = 'http://itunes.com/';
$itunes_song = str_replace("'", '', $str);
$args = array(
'term' => $itunes_song,
'entity' => 'song',
'limit' => '1',
);
echo $song_itunes;
$url = "https://itunes.apple.com/search?";
foreach ($args as $key => $val) {
$url .= $key . '=' . rawurlencode($val) . '&';
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $manual_referer);
$body = curl_exec($ch);
curl_close($ch);
$json = json_decode($body, true);
$results = $json['results'];
foreach ($results as $result) {
$res = $result['artworkUrl100'];
}
now, my problem is: Let's say the song's name is: T Pain - 5 O'Clock,
because the system have a problem with songs with the single quote, i did
these two lines:
$itunes_song = str_replace("'", '', $str);
and
'term' => $itunes_song,
but the output of $itunes_song is: T Pain - 5 O'Clock when it's need to be
T Pain - 5 OClock (without the single quote).
i have no idea what i'm doing wrong here, can anyone help me please? :(
No comments:
Post a Comment