It worked better after using the expression that you posted, but it not quite as I expected. Here is my actual code: <?php //all my precreated functions. I have two in there that I use encrypt_data() and decrypt_data() require "vigilsreign/functions.php"; $string= '<a href="http://example.com">example</a><a href="http://example2.com">example</a>'; $pattern = '/(?<=href=")(.*?)(?=")/'; preg_match($pattern,$string,$match); $y = 0; while ($match[$y]) { $pattern = '/href\="/'; $replacement = ''; $match[$y] = preg_replace($pattern,$replacement,$match[$y]); $pattern = '/"/'; $replacement = ''; $match[$y] = preg_replace($pattern,$replacement,$match[$y]); $url = parse_url($match[$y]); if (!isset($url[scheme])) { $url[scheme] = "http"; } if (!isset($url[host])) { $nothing = decrypt_data($_GET[variable]); $hmmm = parse_url($nothing); $url[host] = $hmmm[host]; } $hmmm = "$url[scheme]://$url[host]$url[path]"; $hmmm = encrypt_data($hmmm); $pattern = "/http:\/\/$url[host]/"; $replacement = "vigilsreign/proxy.php?page=1&&variable=$hmmm"; $string = preg_replace($pattern,$replacement,$string); ++$y; } ?> the array $matches show's like this: Array ( [0] => http://myspace.com [1] => http://myspace.com ) when I want it to show like this: Array ( [0] => http://example.com [1] => http://example2.com )