STR_REPLACE with Array

Asked

Viewed 35 times

0

How do I exchange the space for %20 with values that come from an Array? I got this far by following examples, but it keeps going wrong:

foreach ($jsonArr['data'] as $row) {
    $nome[] = $row['artist']['name']; //artista
    $titulo[] = $row['title'];//nome da música
    $musica[] = $row['preview'];//audio de 30 segundos
    $album[] = $row['album']['cover_xl'];//foto do album 
    $titulo2 = str_replace(array(' ', '%20'), '', $titulo);
    echo $titulo2; }

I need this to put in the url of another API

1 answer

0

I’ll leave the solution here, you can help someone.

$i = 0;
foreach ($jsonArr['data'] as $row) {
    $nome[] = $row['artist']['name']; //artista
    $titulo[] = $row['title'];//nome da música
    $musica[] = $row['preview'];//audio de 30 segundos
    $album[] = $row['album']['cover_xl'];//foto do album 
    $titulo2 = str_replace(' ', '%20', $titulo[$i]);
    echo $titulo2;
$i++;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.