C:\xampp\htdocs\kptv2\admin2\services\test.php


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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
    $response 
'youtube("asdadada", "123")';
    
// function parameters
    /*preg_match('/([\w\_\d]+)\(([\w\W]*)\)/', $response, $matches);
    print_r("fctname " . $matches[1]);
    $params = explode(",", $matches[2]);
    print_r("PARAMS ");
    print_r($params);*/

    // match a single character
    
$str "Jack is a boy";
    
preg_match('/a/'$str$matches);
    
print_r("<strong>Single character /a/</strong><br>");
    
print_r($matches);
    
print_r("<br><br>");

    
// CHARACTER CLASSES
    // mathches only one out of serveral characters
    
print_r("<strong>Single character /J[a]ck/</strong><br> " $str);
    
preg_match_all('/J[a]ck/'$str$matches);
    
print_r($matches);
    
print_r("<br>");
    
$str "Jeck is a boy";
    
print_r("<strong>Single character /J[ae]ck/</strong><br> " $str);    
    
preg_match_all('/J[ae]ck/'$str$matches);
    
print_r($matches);
    
print_r("<br><br>");

    
// match ranges
    
$str "Jack is a boy";
    
print_r("<strong>Match single character in range /J[a-z]ck/</strong><br> " $str);
    
print_r("<br>");
    
preg_match_all('/J[a-z]ck/'$str$matches);
    
print_r($matches);
    
print_r("<br><br>");

    
// negate character class
    
$str "Jack is a boy";
    
print_r("<strong>Negate character class /J[^b]ck/</strong><br> " $str);
    
print_r("<br>");
    
preg_match_all('/J[^b]ck/'$str$matches);
    
print_r($matches);
    
print_r("<br><br>");


    
// shorthand character classes
    // Match single character digit
    
$str "Jack 1 is a boy";
    
print_r("<strong>Match single character digit /\d/</strong><br> " $str);
    
print_r("<br>");
    
preg_match_all('/\d/'$str$matches);
    
print_r($matches);
    
print_r("<br><br>");

    
// Match a word (alphanumeric plus underscore only)
    
$str "Jack is a boy$";
    
print_r("<strong>Match a word (alphanumeric plus underscore only) /\w/</strong><br> " $str);
    
print_r("<br>");
    
preg_match_all('/\w/'$str$matches);
    
print_r($matches);
    
print_r("<br><br>");



    
// Match a word boundary (alphanumeric plus underscore only)
    // if it is on a boundary like /b /b
    
$str "Jack4 is a 4boy ";
    
print_r("<strong>Match a word boundary /\b/</strong><br> " $str);
    
print_r("<br>");
    
preg_match_all('/\b4/'$str$matches);
    
print_r($matches);
    
$str "Jack4 is a boy 44";
    
print_r("<br><br>");


    
// Match whitespace character
    // other : \t - tab, \r - carriage return, \n - line feed, \a - bell, \e - escape etc
    
$str "Jack is a boy$";
    
print_r("<strong>Match whitespace character /\s/</strong><br> " $str);
    
print_r("<br>");
    
preg_match_all('/\s/'$str$matches);
    
print_r($matches);
    
print_r("<br><br>");

    
// Match any character (almost)    
    
$str "Jack and Jaek is a boy$";
    
print_r("<strong>Match any character (almost) /Ja.k/</strong><br> " $str);
    
print_r("<br>");
    
preg_match_all('/Ja.k/'$str$matches);
    
print_r($matches);
    
print_r("<br><br>");

    
// ANCHORS
    // match position - start or end 
    // ^ matches at the start of the string
    // $ matches at the end of the string
    
$str "Jack and Jaek is a boy$";
    
print_r("<strong>Match any character (almost) /Ja.k/</strong><br> " $str);
    
print_r("<br>");
    
preg_match_all('/^J/'$str$matches);
    
print_r($matches);
    
print_r("<br><br>");


    
// REPETITION
    // The question mark makes the preceding token in the regular expression optional
    
$str "Jack and Jak is a boy$";
    
print_r("<strong>preceding token in the regular expression optional /Jac?k/</strong><br> " $str);
    
print_r("<br>");
    
preg_match_all('/Jac?k/'$str$matches);
    
print_r($matches);
    
print_r("<br><br>");

    
// The * tells the engine to attempt to match the preceding token ZERO or more times
    
$str "Jack and Jak is a boy <1>";
    
print_r("<strong>* tells the engine to attempt to match the preceding token ZERO or more times /[^y]<[A-Za-z0-9]*>/</strong><br> " $str);
    
print_r("<br>");
    
preg_match_all('/[^y]<[A-Za-z0-9]*>/'$str$matches);
    
print_r($matches);
    
print_r("<br><br>");


    
// The + tells the engine to attempt to match the preceding token once or more
    
$str "Jack and Jak is a boy <1> <>";
    
print_r("<strong>+ tells the engine to attempt to match the preceding token ONCE or more /<[A-Za-z0-9]+>/</strong><br> " $str);
    
print_r("<br>");
    
preg_match_all('/<[A-Za-z0-9]+>/'$str$matches);
    
print_r($matches);
    
print_r("<br> versus * (zero or more)");
    
preg_match_all('/<[A-Za-z0-9]*>/'$str$matches);
    
print_r($matches);
    
print_r("<br><br>");
 
    
// The {} specify a specific amount of repetition {min,max}
    
$str "1111 999999";
    
print_r("<strong>The {} specify a specific amount of repetition /<[A-Za-z0-9]+>/</strong><br> " $str);
    
print_r("<br>");
    
// what is this, 
    // [1-9] - only once since number can't start with 0
    // [0-9] - repeat minum 3 maximum 4 times
    
preg_match_all('/[1-9][0-9]{3,4}/'$str$matches);
    
print_r($matches);    
    
print_r("<br><br>");


?>
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586