Merge pull request #2151 from cryode/feature/output-cache-improvements

Add headers to Output class cache files.
diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php
index 0c0edf5..130f6f9 100644
--- a/system/helpers/url_helper.php
+++ b/system/helpers/url_helper.php
@@ -408,23 +408,18 @@
 			}
 		}
 
-		if ($type !== 'url' && preg_match_all('/([a-zA-Z0-9_\.\-\+]+)@([a-zA-Z0-9\-]+)\.([a-zA-Z0-9\-\.]+)/i', $str, $matches))
+		if ($type !== 'url' && preg_match_all('/([a-zA-Z0-9_\.\-\+]+)@([a-zA-Z0-9\-]+)\.([a-zA-Z0-9\-\.]+)/i', $str, $matches, PREG_OFFSET_CAPTURE))
 		{
-			for ($i = 0, $c = count($matches); $i < $c; $i++)
+			for ($i = count($matches[0]) - 1; $i > -1; $i--)
 			{
-				if (preg_match('/(\.|\,)$/i', $matches[3][$i], $m))
+				if (preg_match('/(\.|\,)$/i', $matches[3][$i][0], $m))
 				{
-					$punct = $m[1];
-					$matches[3][$i] = substr($matches[3][$i], 0, -1);
-				}
-				else
-				{
-					$punct = '';
+					$matches[3][$i][0] = substr($matches[3][$i][0], 0, -1);
 				}
 
-				if (filter_var(($m = $matches[1][$i].'@'.$matches[2][$i].'.'.$matches[3][$i]), FILTER_VALIDATE_EMAIL) !== FALSE)
+				if (filter_var(($m = $matches[1][$i][0].'@'.$matches[2][$i][0].'.'.$matches[3][$i][0]), FILTER_VALIDATE_EMAIL) !== FALSE)
 				{
-					$str = str_replace($matches[0][$i], safe_mailto($m).$punct, $str);
+					$str = substr_replace($str, safe_mailto($m), $matches[0][$i][1], strlen($m));
 				}
 			}
 		}