Table of Contents

substr

WMPRO, WMMINI FW >= 1.0 WMMEGA FW >= 2.0

Return part of a string

Description

string substr ( string $input, int $start [, int $length ] )

This function returns a substring of a string as specified by the start and length parameters

Parameters

$input: The input string. Must be one character or longer.

$start: The starting position in the input string for the returned substring, counting from zero.

$length: Optional limit to the number of characters returned. If not specified the function will return all of the characters from start until the end of the input string.

Note

Wattmon uPHP does not support negative start or length parameters as in mainline PHP.

Return Values

String: Substring extracted from the input string.

This can be an empty string if the length of the input string is less than or equal to start, or if length = 0 is specified.

Examples

<pre><?
  print(substr('abcdef',1)."\r\n");    // bcdef
  print(substr('abcdef',1,3)."\r\n");  // bcd
  print(substr('abcdef',0,4)."\r\n");  // abcd
  print(substr('abcdef',0,8)."\r\n");  // abcdef
  print(substr('abcdef',6)."\r\n");    // (empty string)
  print(substr('abcdef',1,0)."\r\n");  // (empty string)
?></pre>

See Also

charat() - Return the ASCII code for a character in a string at an index

strlen() - Return the length of a string

strpos() - Return the position of the first occurrence of a needle in a haystack

strrpos() - Return the position of the last occurrence of a needle in a haystack

strtolower() - Return the lowercase version of a string

strtoupper() - Return the UPPERCASE version of a string

ucfirst() - Convert a string to lowercase except for the first character