PHP

substr 문자열자르기

이상욱1 2015. 7. 28. 19:21

http://php.net/manual/kr/function.substr.php

설명 ¶

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

Returns the portion of string specified by the start and length parameters.

인수 ¶

string

The input string. Must be one character or longer.

start

If start is non-negative, the returned string will start at the start'th position in string, counting from zero. For instance, in the string 'abcdef', the character at position 0 is 'a', the character at position 2 is 'c', and so forth.

If start is negative, the returned string will start at the start'th character from the end of string.

If string is less than or equal to start characters long, FALSE will be returned.

Example #1 Using a negative start

<?php
$rest 
substr("abcdef", -1);    // returns "f"
$rest substr("abcdef", -2);    // returns "ef"
$rest substr("abcdef", -31); // returns "d"
?>
length