In PHP, the iconv_substr() function is used to cut a part of the specified string through the offset and length parameters. Suppose we have a string "helloWorld" and we just want to cut and display the string (llowo) then we will use a number between 2 and 5 to select it .
string iconv_substr(str $string, int $offset, int $length, str $encoding)
iconv_substr()Accepts four parameters: $string, $offset, $length and $encoding.
$string− The $string parameter specifies the original encoding
$offset− If $ If the offset parameter is non-negative, the iconv_substr() function will cut the selected part of the string starting from the offset character, counting from zero. If negative, the iconv_substr() function cuts the portion starting at that position, offset by characters from the end of the string.
$length− If the $length argument is given and is positive, the return value contains at most length characters starting at offset .
$encoding− If the encoding argument is absent or null, the string is assumed to be in iconv.internal_encoding.
iconv_substr()The function returns the portion of the string specified by the offset and length parameters. Returns False if the string is shorter than the offset characters. If the string is exactly the same length as the offset characters, null or an empty string will be returned.
<?php // Helloworld sting is used // To cut the selected portion from string //iconv_substr function is used $string = iconv_substr("HelloWorld!", 2, 7, "UTF-8"); // It will returns the character from 2 to 7 var_dump($string); ?>
string(7) "lloWorl"
<?php // Helloworld sting is used // To cut the selected portion from string //iconv_substr function is used $string = iconv_substr ("Hello World!", 2, 7, "UTF-8"); // It will returns the character from 2 to 7 var_dump($string); ?gt;
string(7) "llo Wor"
The above is the detailed content of PHP - How to use iconv_substr() function to intercept part of a string?. For more information, please follow other related articles on the PHP Chinese website!