Ideally I want to use the php script as an include that will be on every page.
I have link: http://www.facebook.com/sharer.php?u=http://123.456.789.101/~user/file.php
and I want to make it look like this: http://www.facebook.com/sharer.php?u=http://MyUrl.com/file.php
Essentially I want to replace “123.456.789.101/~user” with “MyUrl.com”
There will be multiple links that I am going to need to change. Also, the file name “file.php” part changes for each page. I will not know what the exact page name will be.
I tried this but it does not work. If I echo the str_replace it gives me the correct link but I can not get the new link to replace the old link in the page.
<?php
$string = 'http://www.facebook.com/sharer.php?u=http://123.456.789.101/~user';
$pattern = '123.456.789.101/~user';
$replacement = 'MyUrl.com';
str_replace($pattern, $replacement, $string);
?>
Thank you so much.
Try this
To replace in html use: