PHP Класс str, kirby

Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
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

Описание методов

apostrophe() статический публичный Метод

Adds an apostrohpe to a string/name if applicable
static public apostrophe ( string $name ) : string
$name string The string to be shortened
Результат string The string + apostrophe

contains() статический публичный Метод

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
Результат string

cutout() статический публичный Метод

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.
Результат string The shortened string

email() статический публичный Метод

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.
Результат string

encode() статический публичный Метод

Encode a string (used for email addresses)
static public encode ( string $string ) : string
$string string
Результат string

entities() статический публичный Метод

An internal store for a html entities translation table
static public entities ( ) : array
Результат array

excerpt() статический публичный Метод

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.
Результат string The shortened string

html() статический публичный Метод

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.
Результат string The html string

length() статический публичный Метод

An UTF-8 safe version of strlen()
static public length ( string $str ) : string
$str string
Результат string

lower() статический публичный Метод

An UTF-8 safe version of strtolower()
static public lower ( string $str ) : string
$str string
Результат string

match() статический публичный Метод

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
Результат mixed

parse() статический публичный Метод

Available methods: - json - xml - url - query - php
static public parse ( string $string, string $mode = 'json' ) : string
$string string
$mode string
Результат string

plural() статический публичный Метод

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
Результат string The string

random() статический публичный Метод

Generates a random string
static public random ( integer $length = false ) : string
$length integer The length of the random string
Результат string

sanitize() статический публичный Метод

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
Результат string The sanitized string

short() статический публичный Метод

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.
Результат string The shortened string

shorturl() статический публичный Метод

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.
Результат string The shortened URL

split() статический публичный Метод

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.
Результат array An array of found values

stripslashes() статический публичный Метод

A better way to strip slashes
static public stripslashes ( string $string ) : string
$string string
Результат string

substr() статический публичный Метод

An UTF-8 safe version of substr()
static public substr ( string $str, integer $start, integer $end = null ) : string
$str string
$start integer
$end integer
Результат string

trim() статический публичный Метод

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
Результат string The trimmed string

ucfirst() статический публичный Метод

An UTF-8 safe version of ucfirst()
static public ucfirst ( $str ) : string
Результат string

ucwords() статический публичный Метод

An UTF-8 safe version of ucwords()
static public ucwords ( $str ) : string
Результат string

unhtml() статический публичный Метод

Removes all html tags and encoded chars from a string
static public unhtml ( string $string ) : string
$string string
Результат string The html string

unxml() статический публичный Метод

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
Результат string

upper() статический публичный Метод

An UTF-8 safe version of strotoupper()
static public upper ( string $str ) : string
$str string
Результат string

urlify() статический публичный Метод

Convert a string to a safe version to be used in an URL
static public urlify ( string $text ) : string
$text string The unsafe string
Результат string The safe string

utf8() статический публичный Метод

Converts a string to UTF-8
static public utf8 ( string $string ) : string
$string string
Результат string

xml() статический публичный Метод

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
Результат string