Topic: preg_replace problem
Can somebody help me with my problem:
I would like to rewrite my lost site from alexa, but the archived pages are full of urls like:
http://web.archive.org/web/20040XXXX/http://site.com , can somebody tell me an easy preg_replace function so i can replace those links into http://site.com ?!
:\
it’s like a rocket science that preg_replace
lol
You could try bypassing regex by exploding the string like so:
$strUrl = 'http://web.archive.org/web/20040XXXX/http://site.com';
$arrUrl = explode('http://', $str);
$strDomain = $arrUrl[count($arrUrl) - 1];
echo $strDomain; // site.com
It assumes the last full URL will always be the one you want. A regex solution might scale better, but it’s a quick and dirty way if the conditions are right.
The archive version will be a single value.
str_replace('http://web.archive.org/web/20040XXXX/','',$thehtml);
Done.
A single page will be, yes, but if you browse other pages of the same version you’ll notice the URL changes.
okay, so…
preg_replace("~http://web.archive.org/web/[\\d]+/~",'',$thehtml)
Wouldn’t you have to escape the forward slashes or am I missing something?
preg_replace('~http:\\/\\/web.archive.org\\/web\\/\\d+\\/~', '', $thehtml)
Forward slashes only need to be escaped if your delimiter is a forward slash. I used the tilde.