Guys,
What I am trying to do is load google.com with cURL and no matter what link is on the page, be it a google link or another domain), I want the script to precede: http://mydomain.com/tracker.php?
So, if the page contains a link like this:
then that should be replaced with:
http://mydomain.com/tracker.php?http://somedomain.com/
And, if the page contains link like this:
http://subdomain.somedomain.com/dir/sub-dir/page.html
Then, I want it to be replaced to:
http://mydomain.com/tracker.php?http://subdomain.somedomain.com/dir/sub-dir/page.html
You get my point ?
Here's my code but I get error:
Warning: preg_replace(): Delimiter must not be alphanumeric or backslash in C:\xampp\htdocs\test\CURL_experiment1.php on line 13
Here's my 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);
$pattern = 'http://';
$replacement = 'http://mydomain.com/tracker.php?';
echo preg_replace($pattern, $replacement, $result);
?>