01 <?php
02
03 // InStr function
04 // checks for an occurance of a string
05 // within another string
06 function InStr($String,$Find,$CaseSensitive = false)
07 {
08 $i=0;
09 while(strlen($String) >= $i)
10 {
11 unset($substring);
12 if($CaseSensitive)
13 {
14 $Find = strtolower($Find);
15 $String = strtolower($String);
16 }
17 $substring = substr($String,$i,strlen($Find));
18 if($substring == $Find) return true;
19 $i++;
20 }
21 return false;
22 }
23
24 // A similar function, returns the number of occurances
25 function InStrCount($String,$Find,$CaseSensitive = false)
26 {
27 $i = 0;
28 $x = 0;
29 while(strlen($String) >= $i)
30 {
31 unset($substring);
32 if($CaseSensitive)
33 {
34 $Find = strtolower($Find);
35 $String = strtolower($String);
36 }
37 $substring = substr($String,$i,strlen($Find));
38 if($substring == $Find) $x++;
39 $i++;
40 }
41 return $x;
42 }
43
44 // Another similar function, this will return the position of
45 // the string. returns -1 if the string does not exist
46 function InStrPos($String,$Find,$CaseSensitive = false)
47 {
48 $i = 0;
49 while(strlen($String) >= $i)
50 {
51 unset($substring);
52 if($CaseSensitive)
53 {
54 $Find = strtolower($Find);
55 $String = strtolower($String);
56 }
57 $substring = substr($String,$i,strlen($Find));
58 if($substring == $Find) return $i;
59 $i++;
60 }
61 return -1;
62 }
63
64 ?>