I did the following:
$link = '\\[url]www.jack.com\jack.jpg[/url]';
$replace=str_replace( "\\", "/", $link);
echo $replace;
And the output:
/www.jack.com/jack.jpg
Now if I use \\www.jack.com\jack.jpg, I get //www.jack.com/jack.jpg.
I'm think you should try the above code to make sure your environment is groovy. And then I'd be a little hesitant about using variable variables. Its made your code rather difficult to read and its hard to tell if str_replace() is getting hung up on it (I didn't have enough info to setup my script with variable variables).