Namespaces

  • Latte
    • Loaders
    • Macros
    • Runtime
  • Nette
    • Application
      • Responses
      • Routers
      • UI
    • Bridges
      • ApplicationDI
      • ApplicationLatte
      • ApplicationTracy
      • CacheDI
      • CacheLatte
      • DatabaseDI
      • DatabaseTracy
      • DITracy
      • FormsDI
      • FormsLatte
      • Framework
      • HttpDI
      • HttpTracy
      • MailDI
      • ReflectionDI
      • SecurityDI
      • SecurityTracy
    • Caching
      • Storages
    • ComponentModel
    • Database
      • Conventions
      • Drivers
      • Reflection
      • Table
    • DI
      • Config
        • Adapters
      • Extensions
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
    • Reflection
    • Security
    • Utils
  • none
  • Tracy
    • Bridges
      • Nette

Classes

  • ArrayHash
  • ArrayList
  • Arrays
  • Callback
  • DateTime
  • FileSystem
  • Finder
  • Html
  • Image
  • Json
  • LimitedScope
  • MimeTypeDetector
  • ObjectMixin
  • Paginator
  • Random
  • Strings
  • TokenIterator
  • Tokenizer
  • Validators

Interfaces

  • IHtmlString

Exceptions

  • AssertionException
  • ImageException
  • JsonException
  • RegexpException
  • TokenizerException
  • UnknownImageFileException
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Other releases
  • Nette homepage

Class Strings

String tools library.

Namespace: Nette\Utils
Located at Utils/Strings.php
Methods summary
final public
# __construct( )

Static class - cannot be instantiated.

Static class - cannot be instantiated.

public static boolean
# checkEncoding( string $s )

Checks if the string is valid for UTF-8 encoding.

Checks if the string is valid for UTF-8 encoding.

Parameters

$s
stream to check

Returns

boolean
bool
public static string
# fixEncoding( string $s )

Removes invalid code unit sequences from UTF-8 string.

Removes invalid code unit sequences from UTF-8 string.

Parameters

$s
stream to fix

Returns

string
string
public static string
# chr( integer $code )

Returns a specific character in UTF-8.

Returns a specific character in UTF-8.

Parameters

$code
point (0x0 to 0xD7FF or 0xE000 to 0x10FFFF)

Returns

string
string

Throws

Nette\InvalidArgumentException
if code point is not in valid range
public static boolean
# startsWith( string $haystack, string $needle )

Starts the $haystack string with the prefix $needle?

Starts the $haystack string with the prefix $needle?

Parameters

$haystack
$needle

Returns

boolean
bool
public static boolean
# endsWith( string $haystack, string $needle )

Ends the $haystack string with the suffix $needle?

Ends the $haystack string with the suffix $needle?

Parameters

$haystack
$needle

Returns

boolean
bool
public static boolean
# contains( string $haystack, string $needle )

Does $haystack contain $needle?

Does $haystack contain $needle?

Parameters

$haystack
$needle

Returns

boolean
bool
public static string
# substring( string $s, integer $start, integer $length = NULL )

Returns a part of UTF-8 string.

Returns a part of UTF-8 string.

Parameters

$s
$start
characters (code points)
$length
characters (code points)

Returns

string
string
public static string
# normalize( string $s )

Removes special controls characters and normalizes line endings and spaces.

Removes special controls characters and normalizes line endings and spaces.

Parameters

$s
encoding

Returns

string
string
public static string
# normalizeNewLines( string $s )

Standardize line endings to unix-like.

Standardize line endings to unix-like.

Parameters

$s
encoding or 8-bit

Returns

string
string
public static string
# toAscii( string $s )

Converts to ASCII.

Converts to ASCII.

Parameters

$s
encoding

Returns

string
ASCII
public static string
# webalize( string $s, string $charlist = NULL, boolean $lower = TRUE )

Converts to web safe characters [a-z0-9-] text.

Converts to web safe characters [a-z0-9-] text.

Parameters

$s
encoding
$charlist
characters
$lower

Returns

string
string
public static string
# truncate( string $s, integer $maxLen, string $append = "\xE2\x80\xA6" )

Truncates string to maximal length.

Truncates string to maximal length.

Parameters

$s
encoding
$maxLen
$append
encoding

Returns

string
string
public static string
# indent( string $s, integer $level = 1, string $chars = "\t" )

Indents the content from the left.

Indents the content from the left.

Parameters

$s
encoding or 8-bit
$level
$chars

Returns

string
string
public static string
# lower( string $s )

Convert to lower case.

Convert to lower case.

Parameters

$s
encoding

Returns

string
string
public static string
# firstLower( string $s )

Convert first character to lower case.

Convert first character to lower case.

Parameters

$s
encoding

Returns

string
string
public static string
# upper( string $s )

Convert to upper case.

Convert to upper case.

Parameters

$s
encoding

Returns

string
string
public static string
# firstUpper( string $s )

Convert first character to upper case.

Convert first character to upper case.

Parameters

$s
encoding

Returns

string
string
public static string
# capitalize( string $s )

Capitalize string.

Capitalize string.

Parameters

$s
encoding

Returns

string
string
public static boolean
# compare( string $left, string $right, integer $len = NULL )

Case-insensitive compares UTF-8 strings.

Case-insensitive compares UTF-8 strings.

Parameters

$left
$right
$len

Returns

boolean
bool
public static string
# findPrefix( string|array $strings )

Finds the length of common prefix of strings.

Finds the length of common prefix of strings.

Parameters

$strings

Returns

string
string
public static integer
# length( string $s )

Returns number of characters (not bytes) in UTF-8 string. That is the number of Unicode code points which may differ from the number of graphemes.

Returns number of characters (not bytes) in UTF-8 string. That is the number of Unicode code points which may differ from the number of graphemes.

Parameters

$s

Returns

integer
int
public static string
# trim( string $s, string $charlist = Nette\Utils\Strings::TRIM_CHARACTERS )

Strips whitespace.

Strips whitespace.

Parameters

$s
encoding
$charlist

Returns

string
string
public static string
# padLeft( string $s, integer $length, string $pad = ' ' )

Pad a string to a certain length with another string.

Pad a string to a certain length with another string.

Parameters

$s
encoding
$length
$pad

Returns

string
string
public static string
# padRight( string $s, integer $length, string $pad = ' ' )

Pad a string to a certain length with another string.

Pad a string to a certain length with another string.

Parameters

$s
encoding
$length
$pad

Returns

string
string
public static string
# reverse( string $s )

Reverse string.

Reverse string.

Parameters

$s
encoding

Returns

string
string
public static
# random( $length = 10, $charlist = '0-9a-z' )

Use Nette\Utils\Random::generate

Use Nette\Utils\Random::generate

Deprecated

public static string|false
# before( string $haystack, string $needle, integer $nth = 1 )

Returns part of $haystack before $nth occurence of $needle.

Returns part of $haystack before $nth occurence of $needle.

Parameters

$haystack
$needle
$nth
value means searching from the end

Returns

string|false
returns FALSE if the needle was not found
public static string|false
# after( string $haystack, string $needle, integer $nth = 1 )

Returns part of $haystack after $nth occurence of $needle.

Returns part of $haystack after $nth occurence of $needle.

Parameters

$haystack
$needle
$nth
value means searching from the end

Returns

string|false
returns FALSE if the needle was not found
public static array
# split( string $subject, string $pattern, integer $flags = 0 )

Splits string by a regular expression.

Splits string by a regular expression.

Parameters

$subject
$pattern
$flags

Returns

array
array
public static mixed
# match( string $subject, string $pattern, integer $flags = 0, integer $offset = 0 )

Performs a regular expression match.

Performs a regular expression match.

Parameters

$subject
$pattern
$flags
be PREG_OFFSET_CAPTURE (returned in bytes)
$offset
in bytes

Returns

mixed
mixed
public static array
# matchAll( string $subject, string $pattern, integer $flags = 0, integer $offset = 0 )

Performs a global regular expression match.

Performs a global regular expression match.

Parameters

$subject
$pattern
$flags
be PREG_OFFSET_CAPTURE (returned in bytes); PREG_SET_ORDER is default
$offset
in bytes

Returns

array
array
public static string
# replace( string $subject, string|array $pattern, string|callable $replacement = NULL, integer $limit = -1 )

Perform a regular expression search and replace.

Perform a regular expression search and replace.

Parameters

$subject
$pattern
$replacement
$limit

Returns

string
string
Constants summary
string TRIM_CHARACTERS
#" \t\n\r\0\x0B\xC2\xA0"
Nette 2.3-20161221 API API documentation generated by ApiGen 2.8.0