Currently I have the following code:
//loop here
foreach ($doc['a'] as $link) {
$href = pq($link)->attr('href');
if (preg_match($url,$href))
{
//delete matched string and append custom url to href attr
}
else
{
//prepend custom url to href attr
}
}
//end loop
Basically I've fetched vial curl an external page. I need to append my own custom URL to each href link in the DOM. I need to check via regex if each href attr already has a base url e.g. www.domain.com/MainPage.html/SubPage.html
If yes, then replace the www.domain.com
part with my custom url.
If not, then simply append my custom url to the relative url.
My question is, what regex syntax should I use and which php function? Is preg_replace() the proper function for this?
Cheers