izk
izk

Reputation: 234

str_replace() not modifying subject parameter by reference

This is my current code:

$parcels = $api->parcels->get(); 
            
$url = (array_values($parcels)[0]['label']['label_printer']);
$goToUrl = $api->getUrl($url);
            
str_replace('/api/v2//api/v2/', '/api/v2/', $goToUrl);
print_r($goToUrl);
echo "<br />";
echo $url;

Why do I use str_replace()? because I am intending to redirect to $goToUrl and this is not working because the current API is giving me the link wrong.

This is my output:

https://api_key:[email protected]/api/v2//api/v2/labels/label_printer/1369315

As you can see, api/v2 comes in this link twice. I want to remove /api/v2/ and then run the output. But my str_replace(); is not performing. My output stays the same.

Can this even be achieved this way?

Upvotes: 0

Views: 75

Answers (1)

Rafael Goulart
Rafael Goulart

Reputation: 293

Try changing the str_replace line to:

$goToUrl = str_replace('/api/v2//api/v2/', '/api/v2/', $goToUrl);

Upvotes: 6

Related Questions