I have a database of articles that contains about 4,000 broken links in roughly 8,000 articles. About half of these broken links follow a pattern that, with the right PHP script, can be used to automatically fix those broken links.
The broken links in question contain links like this:
<a href="http://www.mydomain.tld/article1234-plus-a-slug-
that-varies-in-length.html">some text</a>
The "1234" part represents the unique ID of the article. It can be a three to five digit number between 101 and 10700. The database record for that unique ID contains the correct URL for the page.
I need to identify the strings in the HTML of each article that fit this pattern, extract the "1234" part of the URL, assign it to a $variable, and then replace the URL in the HTML markup of the article for that link with the correct URL taken from the database for that unique ID.
I suspect that preg_match is an appropriate function to use in this case, but I really can't see how to build the PHP script. (My PHP skills aren't great. Neither are my regex skills.) Can anyone help me with a simple script to handle this task?