-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoLinkEmails.php
More file actions
executable file
·70 lines (61 loc) · 2.07 KB
/
AutoLinkEmails.php
File metadata and controls
executable file
·70 lines (61 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* @package Kohana/Codebench
* @category Tests
* @author Geert De Deckere <geert@idoe.be>
*/
class Bench_AutoLinkEmails extends Codebench {
public $description =
'Fixing <a href="http://dev.kohanaphp.com/issues/2772">#2772</a>, and comparing some possibilities.';
public $loops = 1000;
public $subjects = array
(
'<ul>
<li>voorzitter@xxxx.com</li>
<li>vicevoorzitter@xxxx.com</li>
</ul>',
);
// The original function, with str_replace replaced by preg_replace. Looks clean.
public function bench_match_all_loop($subject)
{
if (preg_match_all('~\b(?<!href="mailto:|">|58;)(?!\.)[-+_a-z0-9.]++(?<!\.)@(?![-.])[-a-z0-9.]+(?<!\.)\.[a-z]{2,6}\b~i', $subject, $matches))
{
foreach ($matches[0] as $match)
{
$subject = preg_replace('!\b'.preg_quote($match).'\b!', HTML::mailto($match), $subject);
}
}
return $subject;
}
// The "e" stands for "eval", hmm... Ugly and slow because it needs to reinterpret the PHP code upon each match.
public function bench_replace_e($subject)
{
return preg_replace(
'~\b(?<!href="mailto:|">|58;)(?!\.)[-+_a-z0-9.]++(?<!\.)@(?![-.])[-a-z0-9.]+(?<!\.)\.[a-z]{2,6}\b~ie',
'HTML::mailto("$0")', // Yuck!
$subject
);
}
// This one should be quite okay, it just requires an otherwise useless single-purpose callback.
public function bench_replace_callback_external($subject)
{
return preg_replace_callback(
'~\b(?<!href="mailto:|">|58;)(?!\.)[-+_a-z0-9.]++(?<!\.)@(?![-.])[-a-z0-9.]+(?<!\.)\.[a-z]{2,6}\b~i',
array($this, '_callback_external'),
$subject
);
}
protected function _callback_external($matches)
{
return HTML::mailto($matches[0]);
}
// This one clearly is the ugliest, the slowest and consumes a lot of memory!
public function bench_replace_callback_internal($subject)
{
return preg_replace_callback(
'~\b(?<!href="mailto:|">|58;)(?!\.)[-+_a-z0-9.]++(?<!\.)@(?![-.])[-a-z0-9.]+(?<!\.)\.[a-z]{2,6}\b~i',
create_function('$matches', 'return HTML::mailto($matches[0]);'), // Yuck!
$subject
);
}
}