PHP Class str, kirby

Afficher le fichier Open project: bastianallgeier/kirby Class Usage Examples

Méthodes publiques

Méthode 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 méthode

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

contains() static public méthode

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
Résultat string

cutout() static public méthode

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.
Résultat string The shortened string

email() static public méthode

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.
Résultat string

encode() static public méthode

Encode a string (used for email addresses)
static public encode ( string $string ) : string
$string string
Résultat string

entities() static public méthode

An internal store for a html entities translation table
static public entities ( ) : array
Résultat array

excerpt() static public méthode

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.
Résultat string The shortened string

html() static public méthode

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.
Résultat string The html string

length() static public méthode

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

lower() static public méthode

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

match() static public méthode

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
Résultat mixed

parse() static public méthode

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

plural() static public méthode

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
Résultat string The string

random() static public méthode

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

sanitize() static public méthode

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
Résultat string The sanitized string

short() static public méthode

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.
Résultat string The shortened string

shorturl() static public méthode

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.
Résultat string The shortened URL

split() static public méthode

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.
Résultat array An array of found values

stripslashes() static public méthode

A better way to strip slashes
static public stripslashes ( string $string ) : string
$string string
Résultat string

substr() static public méthode

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

trim() static public méthode

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
Résultat string The trimmed string

ucfirst() static public méthode

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

ucwords() static public méthode

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

unhtml() static public méthode

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

unxml() static public méthode

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
Résultat string

upper() static public méthode

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

urlify() static public méthode

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

utf8() static public méthode

Converts a string to UTF-8
static public utf8 ( string $string ) : string
$string string
Résultat string

xml() static public méthode

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
Résultat string