PHP GET STRING

Parameters

string The đầu vào string.

offset

If offset is non-negative, the returned string will start at the offset'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 offmix is negative sầu, the returned string will start at the offset'th character from the end of string.

If string is less than offmix characters long, false will be returned.


(obatambeienwasirherbal.com 4, obatambeienwasirherbal.com.. 5, obatambeienwasirherbal.com 7, obatambeienwasirherbal.comhường 8)

substr — Return part of a string


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

length

If length is given và is positive sầu, the string returned will contain at most length characters beginning from offmix (depending on the length of string).

If length is given và is negative sầu, then that many characters will be omitted from the over of string (after the start position has been calculated when a offset is negative). If offphối denotes the position of this truncation or beyond, false will be returned.

If length is given & is 0, false or null, an empty string will be returned.

If length is omitted, the substring starting from offmix until the kết thúc of the string will be returned.


(obatambeienwasirherbal.comhường 4, obatambeienwasirherbal.com.. 5, obatambeienwasirherbal.com 7, obatambeienwasirherbal.com 8)

substr — Return part of a string


$rest substr("abcdef"0, -1);  // returns "abcde"
$rest substr("abcdef"2, -1);  // returns "cde"
$rest substr("abcdef"4, -4);  // returns false
$rest substr("abcdef", -3, -1); // returns "de"
?>

Return Values

Returns the extracted part of string; or false on failure, or an empty string.


Changelog

Version Description 8.0.0 length is nullable now. 8.0.0 The function returns an empty string where it previously returned false.

(obatambeienwasirherbal.com 4, obatambeienwasirherbal.com.. 5, obatambeienwasirherbal.com 7, obatambeienwasirherbal.comhường 8)

substr — Return part of a string


(obatambeienwasirherbal.comhường 4, obatambeienwasirherbal.com 5, obatambeienwasirherbal.com. 7, obatambeienwasirherbal.comhường. 8)

substr — Return part of a string


echo substr("abcdef"1);     // bcdef
echo substr("abcdef"13);  // bcd
echo substr("abcdef"04);  // abcd
echo substr("abcdef"08);  // abcdef
echo substr("abcdef", -11); // f

// Accessing single characters in a string
// can also be achieved using "square brackets"
$string "abcdef";
echo 
$string<0>;                 // a
echo $string<3>;                 // d
echo $string<strlen($string)-1>; // f

?>

Example #4 substr() casting behaviour


class apple 
}

echo 
"1) ".

Bạn đang xem: Php get string

var_export(substr("pear"02), true).obatambeienwasirherbal.com_EOL;
echo 
"2) ".var_export(substr(5432102), true).obatambeienwasirherbal.com_EOL;
echo 
"3) ".var_export(substr(new apple(), 02), true).obatambeienwasirherbal.com_EOL;
echo 
"4) ".

Xem thêm: Lnp Là Gì ? Lợi Ích Lập Trình Ngôn Ngữ Tư Duy Nlp Đem Lại Khóa Học Nlp Là Gì

var_export(substr(true01), true).obatambeienwasirherbal.com_EOL;
echo 
"5) ".var_export(substr(false01), true).obatambeienwasirherbal.com_EOL;
echo 
"6) ".var_export(substr(""01), true).obatambeienwasirherbal.com_EOL;
echo 
"7) ".var_export(substr(1.2e304), true).obatambeienwasirherbal.com_EOL;
?>

Output đầu ra of the above sầu example in obatambeienwasirherbal.comhường 7:


1) 'pe' 2) '54' 3) 'gr' 4) '1' 5) '' 6) '' 7) '1200'

Output of the above example in obatambeienwasirherbal.comhường 5:


1) 'pe' 2) '54' 3) 'gr' 4) '1' 5) false 6) false 7) '1200'

Errors/Exceptions

Returns false on error.
var_dump(substr("a"2)); // bool(false)
?>

See Also

strrchr() - Find the last occurrence of a character in a string substr_replace() - Replace text within a portion of a string preg_match() - Persize a regular expression match trim() - Strip whitespace (or other characters) from the beginning và kết thúc of a string mb_substr() - Get part of string wordwrap() - Wraps a string to lớn a given number of characters String access & modification by character