Unstoppable Domains

Preg replace - Replace links

Spaceship Spaceship
Watch

ubzweb

Established Member
Impact
6
Hi there,

I have a a large number of pages in which I want to replace parts of links within it. Ill give an example
This is the html I am getting from a function:
Code:
<p>In most <a href=\"/toreplace/Bird\" title=\"Bird\">birds</a> and <a href=\"/toreplace/Reptile\" title=\"Reptile\">reptiles</a>, an <b>egg</b> is the <a href=\"/toreplace/Zygote\" title=\"Zygote\">zygote</a>, resulting from <a href=\"/toreplace/Fertilization\" title=\"Fertilization\">fertilization</a> of the <a href=\"/toreplace/Ovum\" title=\"Ovum\">ovum</a>. It nourishes and protects the <a href=\"/toreplace/Embryo\" title=\"Embryo\">embryo</a>.
I want to replace all the links in it for ex:
Code:
<a href=\"/toreplace/Bird\" title=\"Bird\">birds</a>
with
Code:
<a href=\"/Bird.html\" title=\"Bird\">birds</a>
That is I want to remove the text "toreplace" and add a .html at the end of the link.

I hope this is possible using php regex and I am at the right place amongst the right people.
Any help would be appreciated. Thanks a lot
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable DomainsUnstoppable Domains
untested but may work :D

PHP:
$links = preg_replace('/href=\\\"\\/toreplace\\/([^\\\]+)\\\"/i', 'href=\\"\\1.html\\"', $links );
 
0
•••
Appraise.net

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Live Options
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back