| [ Index ] |
PHP Cross Reference of GlotPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Functions, which make work with strings easier 4 */ 5 6 function gp_startswith( $haystack, $needle ) { 7 return 0 === strpos( $haystack, $needle ); 8 } 9 10 function gp_endswith( $haystack, $needle ) { 11 return $needle === substr( $haystack, -strlen( $needle )); 12 } 13 14 function gp_in( $needle, $haystack ) { 15 return false !== strpos( $haystack, $needle ); 16 } 17 18 /** 19 * Adds a slash after the string, while makes sure not to double it 20 * if it already exists 21 */ 22 function gp_add_slash( $string ) { 23 return rtrim( $string, '/' ) . '/'; 24 } 25 26 if ( function_exists('mb_strtolower') ): 27 function gp_strtolower( $str ) { 28 return mb_strtolower( $str ); 29 } 30 else: 31 function gp_strtolower( $str ) { 32 return strtolower( $str ); 33 } 34 endif; 35 36 if ( function_exists('mb_strlen') ): 37 function gp_strlen( $str ) { 38 return mb_strlen( $str ); 39 } 40 else: 41 function gp_strlen( $str ) { 42 return preg_match_all("/.{1}/us", $str, $dummy); 43 } 44 endif; 45 46 function gp_sanitize_for_url( $name ) { 47 $name = trim( $name ); 48 $name = gp_strtolower( $name ); 49 $name = preg_replace( '/&.+?;/', '', $name ); // kill entities 50 $name = str_replace( '.', '-', $name ); 51 $name = preg_replace('|[#$%&~/.\-;:=,?@\[\]+]|', '', $name); 52 $name = preg_replace( '/\s+/', '-', $name ); 53 $name = preg_replace( '|-+|', '-', $name ); 54 $name = trim($name, '-'); 55 return $name; 56 } 57 58 /** 59 * Similar to {@link esc_attr()}, but double encode entities 60 */ 61 function gp_esc_attr_with_entities( $text ) { 62 $safe_text = wp_check_invalid_utf8( $text ); 63 $safe_text = _wp_specialchars( $safe_text, ENT_QUOTES, false, true ); 64 return apply_filters( 'attribute_escape', $safe_text, $text ); 65 66 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu May 24 03:59:35 2012 | Hosted by follow the white rabbit. |