PHP Class str, kirby

Mostrar archivo Open project: bastianallgeier/kirby Class Usage Examples

Public Methods

Method Description
apostrophe ( string $name ) : string Adds an apostrohpe to a string/name if applicable
contains ( string $str, string $needle, boolean $i = true ) : string Checks if a str contains another string
cutout ( $str, integer $length, string $rep = '…' ) : string Shortens a string by cutting out chars in the middle This method mimicks the shortening which is used for filenames in the Finder
email ( string $email, string $text = false, string $title = false, string $class = false ) : string Creates an encoded email address, including proper html-tags
encode ( string $string ) : string Encode a string (used for email addresses)
entities ( ) : array An internal store for a html entities translation table
excerpt ( string $string, integer $chars = 140, boolean $removehtml = true, string $rep = '…' ) : string Creates an exceprt of a string It removes all html tags first and then uses str::short
html ( string $string, boolean $keep_html = true ) : string Converts a string to a html-safe string
length ( string $str ) : string An UTF-8 safe version of strlen()
link ( string $link, string $text = false ) : string Creates a link tag
lower ( string $str ) : string An UTF-8 safe version of strtolower()
match ( string $string, string $preg, string $get = false, string $placeholder = false ) : mixed preg_match sucks! This tries to make it more convenient
parse ( string $string, string $mode = 'json' ) : string Parses a string by a set of available methods
plural ( integer $count, string $many, string $one, string $zero = '' ) : string A switch to display either one or the other string dependend on a counter
random ( integer $length = false ) : string Generates a random string
sanitize ( string $string, string $type = 'str', string $default = null ) : string A set of sanitizer methods
short ( string $string, integer $chars, string $rep = '…' ) : string Shortens a string and adds an ellipsis if the string is too long
shorturl ( string $url, integer $chars = false, boolean $base = false, string $rep = '…' ) : string Shortens an URL It removes http:// or https:// and uses str::short afterwards
split ( string $string, string $separator = ',', integer $length = 1 ) : array Better alternative for explode() It takes care of removing empty values and it has a built-in way to skip values which are too short.
stripslashes ( string $string ) : string A better way to strip slashes
substr ( string $str, integer $start, integer $end = null ) : string An UTF-8 safe version of substr()
trim ( string $string ) : string A more brutal way to trim.
ucfirst ( $str ) : string An UTF-8 safe version of ucfirst()
ucwords ( $str ) : string An UTF-8 safe version of ucwords()
unhtml ( string $string ) : string Removes all html tags and encoded chars from a string
unxml ( string $string ) : string Removes all xml entities from a string and convert them to html entities first and remove all html entities afterwards.
upper ( string $str ) : string An UTF-8 safe version of strotoupper()
urlify ( string $text ) : string Convert a string to a safe version to be used in an URL
utf8 ( string $string ) : string Converts a string to UTF-8
xml ( string $text, boolean $html = true ) : string Converts a string to a xml-safe string Converts it to html-safe first and then it will replace html entities to xml entities

Method Details

apostrophe() static public method

Adds an apostrohpe to a string/name if applicable
static public apostrophe ( string $name ) : string
$name string The string to be shortened
return string The string + apostrophe

contains() static public method

Checks if a str contains another string
static public contains ( string $str, string $needle, boolean $i = true ) : string
$str string
$needle string
$i boolean ignore upper/lowercase
return string

cutout() static public method

Shortens a string by cutting out chars in the middle This method mimicks the shortening which is used for filenames in the Finder
static public cutout ( $str, integer $length, string $rep = '…' ) : string
$length integer The final number of characters the string should have
$rep string The element, which should be added if the string is too long. Ellipsis is the default.
return string The shortened string

email() static public method

Creates an encoded email address, including proper html-tags
static public email ( string $email, string $text = false, string $title = false, string $class = false ) : string
$email string The email address
$text string Specify a text for the email link. If false the email address will be used
$title string An optional title for the html tag.
$class string An optional class name for the html tag.
return string

encode() static public method

Encode a string (used for email addresses)
static public encode ( string $string ) : string
$string string
return string

entities() static public method

An internal store for a html entities translation table
static public entities ( ) : array
return array

excerpt() static public method

Creates an exceprt of a string It removes all html tags first and then uses str::short
static public excerpt ( string $string, integer $chars = 140, boolean $removehtml = true, string $rep = '…' ) : string
$string string The string to be shortened
$chars integer The final number of characters the string should have
$removehtml boolean True: remove the HTML tags from the string first
$rep string The element, which should be added if the string is too long. Ellipsis is the default.
return string The shortened string

html() static public method

Converts a string to a html-safe string
static public html ( string $string, boolean $keep_html = true ) : string
$string string
$keep_html boolean True: lets stuff inside html tags untouched.
return string The html string

length() static public method

An UTF-8 safe version of strlen()
static public length ( string $str ) : string
$str string
return string

lower() static public method

An UTF-8 safe version of strtolower()
static public lower ( string $str ) : string
$str string
return string

match() static public method

preg_match sucks! This tries to make it more convenient
static public match ( string $string, string $preg, string $get = false, string $placeholder = false ) : mixed
$string string
$preg string Regular expression
$get string Which part should be returned from the result array
$placeholder string Default value if nothing will be found
return mixed

parse() static public method

Available methods: - json - xml - url - query - php
static public parse ( string $string, string $mode = 'json' ) : string
$string string
$mode string
return string

plural() static public method

A switch to display either one or the other string dependend on a counter
static public plural ( integer $count, string $many, string $one, string $zero = '' ) : string
$count integer The counter
$many string The string to be displayed for a counter > 1
$one string The string to be displayed for a counter == 1
$zero string The string to be displayed for a counter == 0
return string The string

random() static public method

Generates a random string
static public random ( integer $length = false ) : string
$length integer The length of the random string
return string

sanitize() static public method

A set of sanitizer methods
static public sanitize ( string $string, string $type = 'str', string $default = null ) : string
$string string The string to sanitize
$type string The method
$default string The default value if the string will be empty afterwards
return string The sanitized string

short() static public method

Shortens a string and adds an ellipsis if the string is too long
static public short ( string $string, integer $chars, string $rep = '…' ) : string
$string string The string to be shortened
$chars integer The final number of characters the string should have
$rep string The element, which should be added if the string is too long. Ellipsis is the default.
return string The shortened string

shorturl() static public method

Shortens an URL It removes http:// or https:// and uses str::short afterwards
static public shorturl ( string $url, integer $chars = false, boolean $base = false, string $rep = '…' ) : string
$url string The URL to be shortened
$chars integer The final number of characters the URL should have
$base boolean True: only take the base of the URL.
$rep string The element, which should be added if the string is too long. Ellipsis is the default.
return string The shortened URL

split() static public method

Better alternative for explode() It takes care of removing empty values and it has a built-in way to skip values which are too short.
static public split ( string $string, string $separator = ',', integer $length = 1 ) : array
$string string The string to split
$separator string The string to split by
$length integer The min length of values.
return array An array of found values

stripslashes() static public method

A better way to strip slashes
static public stripslashes ( string $string ) : string
$string string
return string

substr() static public method

An UTF-8 safe version of substr()
static public substr ( string $str, integer $start, integer $end = null ) : string
$str string
$start integer
$end integer
return string

trim() static public method

It removes double spaces. Can be useful in some cases but be careful as it might remove too much.
static public trim ( string $string ) : string
$string string The string to trim
return string The trimmed string

ucfirst() static public method

An UTF-8 safe version of ucfirst()
static public ucfirst ( $str ) : string
return string

ucwords() static public method

An UTF-8 safe version of ucwords()
static public ucwords ( $str ) : string
return string

unhtml() static public method

Removes all html tags and encoded chars from a string
static public unhtml ( string $string ) : string
$string string
return string The html string

unxml() static public method

Removes all xml entities from a string and convert them to html entities first and remove all html entities afterwards.
static public unxml ( string $string ) : string
$string string
return string

upper() static public method

An UTF-8 safe version of strotoupper()
static public upper ( string $str ) : string
$str string
return string

urlify() static public method

Convert a string to a safe version to be used in an URL
static public urlify ( string $text ) : string
$text string The unsafe string
return string The safe string

utf8() static public method

Converts a string to UTF-8
static public utf8 ( string $string ) : string
$string string
return string

xml() static public method

Converts a string to a xml-safe string Converts it to html-safe first and then it will replace html entities to xml entities
static public xml ( string $text, boolean $html = true ) : string
$text string
$html boolean True: convert to html first
return string