Studyon Minte9.com
ZCE 5.3

Study

Searching



	// strpos(haystack, needle) [, offset] | strpos("abca", "a", 1) = 3 | FALSE
        // strrpos() | last needle occurence
	// strstr(haystack, needle) [, flag] | strstr("name@dot.com", "@", true) = name | FALSE
	// strstr SLOWER than strpos
	// parse_str(query_string) [, arr] | $v1, $v2 OR arr[v1] | NO VALUE
	// parse_url(query_string) | scheme, host, path, query
	// strtok("java.lang.Object", "."); // tok1 = java
	// strtok("."); // tok2 = lang
	// strspn(string, mask) [, start, length] | strlen($phone) == strspn($phone, $allowed)
	// substr ($string , $start) [, $length ] | substr("123456", -3, 1) = 4
        // str_word_count(abc def) = 2 | [, format = 1] Array(words)
        // count_chars(str) [, mode] | chr
        // substr_count(This is a test, is); // 2

        // date

* strpos(), stripos(), strrpos(), strripos()

<?php // Find the position of the first occurrence of a substring in a string echo strpos("abc", "a"); // 0 echo strpos("abca", "a", 1); // 3 echo strpos("abcaa", "a", 4); // 4 echo stripos("Abc", "a"); // 0 (case insensitive) echo strpos("route_OLD", "_OLD"); // Output: 5 echo strrpos("route_OLD_OLD", "_OLD"); // Output: 9 - reverse // Find the position of the last occurrence of a substring in a string echo strpos('abc', 'd') === FALSE; // 1 echo strpos('abc', 'd') === NULL; // 0
 
<?php // Find the position of the last occurrence of a substring in a string echo strripos("abcB", "b"); // 3
  * strstr(), stristr()
<?php // This function returns the portion of the haystack that starts with the needle echo strstr("name@dot.com", "@"); // Output: @dot.com echo strstr("name@dot.com", "@", true); // Output: name
  In general, strstr() is slower than strpos() - therefore, you should use the latter if your only goal is to determine whether a certain needle occurs inside the haystack. * parse_str ()
<?php // Parses the string into variables // test.php?a=1&&c[]=3&c[]=4 parse_str($_SERVER['QUERY_STRING']); echo $a; // 1 echo $c[1]; // 4
  * parse_url()
<?php // Parse a URL and return its components $parts = parse_url("http://doc.com/test.php?a=1&b=c"); print_r($parts); /* Array ( [scheme] => http [host] => doc.com [path] => /test.php [query] => a=1&b=c ) */
  * strtok(), strrtok()
<?php // Splits a string (str) into smaller strings (tokens) $str = "java.lang.Object"; echo $tok_1 = strtok("java.lang.Object", "."); // java echo $tok_2 = strtok("."); // lang // Get the last part of a string after a given character echo strrev(strtok(strrev("java.lang.Object"), ".")); // tcejbO.gnal.avaj -> tcejbO -> Object
 
<?php // like strstr() echo strtok("name@doc.com", "@"); // name
  * strspn() Match a string against a "whitelist" mask of allowed characters
<?php // Returns the length of the initial segment of the string that does contain // any of the characters from the mask echo strspn("133445ab123ef", "12345"); // 6 echo strspn("133ab12345ef", "12345"); // 3 echo strspn("ab12345ef", "12345"); // 0 // Using a start & length to search echo strspn("ab12345ef", "12345", 2); // 5 echo strspn("ab12345ef", "12345", 2, 1); // 1
 
<?php // You can use this function with strlen to check illegal characters. // This function is significantly faster than the equivalent preg_match() $allowed = "0123456789+. "; $phone = "Phone: +021 072.88.544545"; $phone2 = "+021 072.88.544545 (phone)"; echo strspn($phone, $allowed); // 0 echo strspn($phone2, $allowed); // 19 $allowed = "0123456789+. "; $phone = "+021 / 072.88.544545"; if (strlen($phone) == strspn($phone, $allowed)) { echo "allowed"; // not true becouse of "/" char }
  * substr()
<?php // Allows you to extract a substring from a larger string echo substr("123456", 0); // 123456 echo substr("123456", -1); // 6 echo substr("123456", -2); // 56 echo substr("123456", -3, 1); // 4
  * count_chars()
<?php // Return information about characters used in a string $str = "aAba"; echo count($str); // Output: 1 foreach(count_chars($str, 1) as $k=>$v) { echo "{$v} appearences of the " . chr($k); } // 1 appearences of the A // 2 appearences of the a // 1 appearences of the b
  * str_word_count()
<?php // Return information about words used in a string echo str_word_count('abc def ghi'); // Output: 3 print_r(str_word_count('abc def ghi', 1)); // Output: Array ( [0] => abc [1] => def [2] => ghi )
  * mktime
<?php // mktime(h,m,s, m,d,y) // date(format) [,mktime] date_default_timezone_set('UTC'); // Without it: Warning - It is not safe to rely on the system's timezone settings echo $mktime = mktime(12,0,0, 2,8,1974); // 129556800 echo date('Y-m-d h:i:s'); // 2012-11-10 12:14:50 echo date('Y-m-d h:i:s', $mktime); // 1974-02-08 12:00:00
  * strtotime
<?php // parse English textual datetime into UNIX timestamp echo strtotime("10 September 2000"); // 968544000
  * strftime
<?php // Format a local time/date according to locale settings setlocale(LC_TIME, "de_DE"); echo strftime("%A"); // Samstag // only if you have the respective locales installed in your system
  * checkdate
<?php // Validate a Gregorian date echo checkdate(2, 28, 2001); // true echo checkdate(2, 29, 2001); // false