I am trying to use PHP to change all dynamic URLs inside a div to a different, static URL.
For example I have:
<div class="mydiv">
<a href="http://oldsite.com/123">Title 123</a>
<a href="http://oldsite.com/321">Title 321</a>
<a href="http://oldsite.com/abc">Title abc</a>
<a href="http://oldsite.com/cba">Title cba</a>
</div>
and I want to change them all to:
<div class="mydiv">
<a href="http://newsite.com">Title 123</a>
<a href="http://newsite.com">Title 321</a>
<a href="http://newsite.com">Title abc</a>
<a href="http://newsite.com">Title cba</a>
</div>
I understand that I could do this with htaccess, but would prefer to do it in PHP if its possible. Any ideas?
EDIT: The oldsite.com links were generated from an RSS feed and are being embedded onto the page. I want all the RSS title links to just send the user to the new site home page.
str_replace takes 3 parameters. The first is what you want to be changed (needle), the second is what you want it changed to, and the third is what you are looking in (haystack).
You could also use an inline ternary operator: