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
|
<?php /* * Foo Functions - Strings * A bunch of common and useful functions related to strings * * Author: Brad Vincent * Author URI: http://fooplugins.com * License: GPL2 */
if ( !function_exists( 'foo_convert_to_key' ) ) { function foo_convert_to_key($input) { return str_replace( " ", "_", strtolower( $input ) ); } }
if ( !function_exists( 'foo_title_case' ) ) { function foo_title_case($input) { return ucwords( str_replace( array("-", "_"), " ", $input ) ); } }
if ( !function_exists( 'foo_contains' ) ) { /* * returns true if a needle can be found in a haystack */ function foo_contains($haystack, $needle) { if ( empty($haystack) || empty($needle) ) { return false; }
$pos = strpos( strtolower( $haystack ), strtolower( $needle ) );
if ( $pos === false ) { return false; } else { return true; } } }
if ( !function_exists( 'foo_starts_with' ) ) { /** * starts_with * Tests if a text starts with an given string. * * @param string * @param string * * @return bool */ function foo_starts_with($haystack, $needle) { return strpos( $haystack, $needle ) === 0; } }
if ( !function_exists( 'foo_ends_with' ) ) { function foo_ends_with($haystack, $needle, $case = true) { $expectedPosition = strlen( $haystack ) - strlen( $needle );
if ( $case ) { return strrpos( $haystack, $needle, 0 ) === $expectedPosition; }
return strripos( $haystack, $needle, 0 ) === $expectedPosition; } }
|