themanwhowas wrote:the backslashes were also printed .
That's because you're using single quotes. PHP doesn't treat "/" as special, so it left "\/" unchanged: the backslashes would be picked up by PCRE because in that "/" did have a special meaning (it was the character you'd chosen as the pattern delimiter).
escaping the slashes in preg_replace still didnt work
<?php
$incData = "This is a string with the test url http://mysite.com/otherstuff/test.html embedded within it.";
$pattern = '/http:\/\/mysite.com\/otherstuff\/test.html/';
$replacement = 'http://mysite.com/otherstuff/test2.html';
echo preg_replace($pattern, $replacement, $incData);
Worked just fine for me.
On an educational note, mysite.com is a real address. If you want a domain name to use in examples, RFC2606 reserves example.com for the purpose.