Have a look at the source code of the page being generated. It works for me, in the sense that forward slashes are not removed.
However there is problem with your code:
style="background-image:url("<?=$img?>");"
You have double quotes within double quotes. That will not work :)
you want this instead
style="background-image:url('<?=$img?>');"
<-- inner double quotes replaced with single quotes.
Other than that your code renders as expected.