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 thestart
'th position instring
, 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 thestart
'th character from the end ofstring
.If
string
is less than or equal tostart
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", -3, 1); // returns "d"
?>length