-
Notifications
You must be signed in to change notification settings - Fork 1
/
preg_match.html
54 lines (36 loc) · 986 Bytes
/
preg_match.html
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
<html><head><title>preg_match example with PHP</title></head>
<body>
<table summary='match results'>
<?php
function does_match($p, $t) {
print "<tr><td>$t</td><td>";
if (preg_match($p, $t)) {
print "matches";
}
else {
print "doesn't match";
}
print "</td><td>$p</td></tr>";
}
$pattern = '/foo/i';
$with_foo = 'I have a Foo.';
$no_foo = 'I do not.';
does_match($pattern, $with_foo);
does_match($pattern, $no_foo);
$pattern = '/\[in\]/';
$in_1 = 'does [in] match?';
$in_2 = 'does in match?';
$pattern = '/[in]/';
$in_1 = 'abcdefgh jklm opqrs uvwxyz';
$in_2 = 'abdef ghij lm opq stu wxyz';
does_match($pattern, $in_1);
does_match($pattern, $in_2);
$pattern = '/end$/';
$dollar_1= 'at the end';
$dollar_2= 'at the end NOT';
does_match($pattern, $dollar_1);
does_match($pattern, $dollar_2);
?>
</table>
<p>See also <a href='preg_replace.html'>preg_replace.html</a>.
</body><html>