Folks,
I’m afraid the following preg_replace is not doing the job. Can you think of a better one ?
Actually, if you can come-up with one that does the following then I’d appreciate it:
1. Replace ‘https://’ with: ‘2. Replace ‘http://’ with: ‘3. Replace ‘www.’ with: ‘4. Replace all subdomains and sub sub domains etc. with: ‘
eg1. Replace ‘mail.domain.com’ with ‘
eg2. Replace ‘ny.mail.domain.com’ with ‘
eg3. Replace ‘europe.spain.mail.domain.com’ with ‘
eg4. Replace ‘west.europe.deutchland.mail.domain.com’ with ‘
And so on. You get the picture.
I tried the following code but it’s not working. Instead of replacing things with ‘
[code]
<?php
$url = “http://google.com”;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, “$url”);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
curl_close($ch);
$result = preg_replace(“#(<s*as+[^>]*hrefs*=s*[“‘])(?!http)([^”‘>]+)([“‘>]+)#”,’$1http://$url/$2$3’, $result);
echo $result
?>
Cheers!