-1

I have this array:

$array = array('name'=>'test','server'=>'zangarmarsh','fields'=>'items,stats');
$type = 'character';
$r = $client->fetch($type,$array);
echo '<pre>';
print_r($r);
echo '</pre>';

The output:

[result] => Array
        (

            [thumbnail] => hellscream/74/113337162-avatar.jpg
 }

Now I echo out the picture:

echo "<img src='http://render-api-us.worldofwarcraft.com/static-render/us/" . $r['result']['thumbnail'] . "' alt='error'>";

Now i want to change the word "avatar" (from the arrays´ output) with the word "profilemain". I know that you can do it with echo str_replace, but i can´t get it work.

Hertus
  • 147
  • 2
  • 11

2 Answers2

0

This should do the trick:

$image = str_replace("avatar" , "profilemain" , $r['result']['thumbnail'];
  • Thanks. but cant get it to work. I tried it so: `$image = str_replace("avatar" , "profilemain" , $r['result']['thumbnail']; echo "error";` – Hertus Jun 03 '16 at 18:07
0

You could use strpos($yourString, $substring) to get the beginning index of 'avatar', then use the length of 'avatar' to get the end index. Cut away the first and the last parts of the string into two separate string variables, then combine them around the string 'profilemain'.

$thumb = 'hellscream/74/113337162-avatar.jpg';

// This gets you everything up to 'avatar' in $thumb
$thumbPre = substr($thumb, 0, strpos($thumb, 'avatar'));
// This gets you everything after 'avatar' in $thumb   
$thumbPost = substr($thumb, strpos($thumb, 'avatar') + strlen('avatar'));

// Sandwich 'profilemain' in between the two
$newString = $thumbPre.'profilemain'.$thumbPost;

Hopefully that helps!

Brice
  • 107
  • 5