Packages

  • Nette
    • Application
      • Diagnostics
      • Responses
      • Routers
      • UI
    • Caching
      • Storages
    • ComponentModel
    • Config
      • Adapters
      • Extensions
    • Database
      • Diagnostics
      • Drivers
      • Reflection
      • Table
    • DI
      • Diagnostics
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
      • Macros
    • Loaders
    • Localization
    • Mail
    • Reflection
    • Security
      • Diagnostics
    • Templating
    • Utils
      • PhpGenerator
  • NetteModule
  • none

Classes

Exceptions

  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Other releases
  • Nette homepage

Class Strings

String tools library.

Package: Nette\Utils
Author: David Grudl
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, string $encoding = 'UTF-8' )

Checks if the string is valid for the specified encoding.

Checks if the string is valid for the specified encoding.

Parameters

$s
string
byte stream to check
$encoding
string
expected encoding

Returns

boolean
public static string
# fixEncoding( string $s, string $encoding = 'UTF-8' )

Returns correctly encoded string.

Returns correctly encoded string.

Parameters

$s
string
byte stream to fix
$encoding
string
encoding

Returns

string
public static string
# chr( integer $code, string $encoding = 'UTF-8' )

Returns a specific character.

Returns a specific character.

Parameters

$code
integer
codepoint
$encoding
string
encoding

Returns

string
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
string
$needle
string

Returns

boolean
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
string
$needle
string

Returns

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

Does $haystack contain $needle?

Does $haystack contain $needle?

Parameters

$haystack
string
$needle
string

Returns

boolean
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
string
$start
integer
$length
integer

Returns

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
string
UTF-8 encoding or 8-bit

Returns

string
public static string
# toAscii( string $s )

Converts to ASCII.

Converts to ASCII.

Parameters

$s
string
UTF-8 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
string
UTF-8 encoding
$charlist
string
allowed characters
$lower
boolean

Returns

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
string
UTF-8 encoding
$maxLen
integer
$append
string
UTF-8 encoding

Returns

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
string
UTF-8 encoding or 8-bit
$level
integer
$chars
string

Returns

string
public static string
# lower( string $s )

Convert to lower case.

Convert to lower case.

Parameters

$s
string
UTF-8 encoding

Returns

string
public static string
# upper( string $s )

Convert to upper case.

Convert to upper case.

Parameters

$s
string
UTF-8 encoding

Returns

string
public static string
# firstUpper( string $s )

Convert first character to upper case.

Convert first character to upper case.

Parameters

$s
string
UTF-8 encoding

Returns

string
public static string
# capitalize( string $s )

Capitalize string.

Capitalize string.

Parameters

$s
string
UTF-8 encoding

Returns

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
string
$right
string
$len
integer

Returns

boolean
public static integer
# length( string $s )

Returns UTF-8 string length.

Returns UTF-8 string length.

Parameters

$s
string

Returns

integer
public static string
# trim( string $s, string $charlist = " \t\n\r\0\x0B\xC2\xA0" )

Strips whitespace.

Strips whitespace.

Parameters

$s
string
UTF-8 encoding
$charlist
string

Returns

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
string
UTF-8 encoding
$length
integer
$pad
string

Returns

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
string
UTF-8 encoding
$length
integer
$pad
string

Returns

string
public static string
# reverse( string $s )

Reverse string.

Reverse string.

Parameters

$s
string
UTF-8 encoding

Returns

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

Generate random string.

Generate random string.

Parameters

$length
integer
$charlist
string

Returns

string
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
string
$pattern
string
$flags
integer

Returns

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
string
$pattern
string
$flags
integer
can be PREG_OFFSET_CAPTURE (returned in bytes)
$offset
integer
offset in bytes

Returns

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
string
$pattern
string
$flags
integer
can be PREG_OFFSET_CAPTURE (returned in bytes); PREG_SET_ORDER is default
$offset
integer
offset in bytes

Returns

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
string
$pattern
string|array
$replacement
string|callable
$limit
integer

Returns

string
Nette Framework 2.0.18 (for PHP 5.2, un-prefixed) API documentation generated by ApiGen 2.8.0