- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
PHP – How to get the selected part of a string using mb_substr()?
In PHP, mb_substr() is used to return the selected part of a given string. The multibyte safe substr() works based on the number of characters. It counts the position from the starting of the string. It will return 0 for the first character position and 1 for the second position character, and so on.
string mb_substr(str $string, int $start, int $length, str $encoding)
This PHP function accepts four parameters: $string, $start, $length and $encoding.
$string− This parameter is used to extract the substring from the given string.
$string = mb_substr("Welcome to the online tutorials!", 5, 10, "UTF-8");
$start− This parameter returns 0 for the first character from starting if the start is non-negative. For example, if the given string is “abcefg” then the character at the first position is 0 means “a” and so on. If the start string is negative, then it will return the character from the end of the string.
$length− The length parameter is the maximum number of characters to use from the string.
// Length is used from character (5 to 10) (5, 10, "UTF-8");
$encoding− It is used for character encoding. If it is omitted or null, the internal character encoding value will be used.
The multibyte substring function will return the selected portion from the given string by using the start and length parameters.
<?php // the mb_substr function will return // the selected part of string $string = mb_substr("Welcome to the online tutorials!", 5, 10, "UTF-8"); // Convert selected string in upper case $string = mb_convert_case($string, MB_CASE_UPPER, "UTF-8"); // Output will be me to the echo "$string"; ?>
ME TO THE
- PHP – How to cut out part of a string using iconv_substr()?
- substr() function in PHP
- Get Last Part of URL in PHP?
- Explain substr() function in PHP
- How to get the selected index of a RadioGroup in Android using Kotlin?
- How to replace a part of the string (domain name after @) using MySQL?
- Get part of a string based on a character in MySQL?
- How to get the length of longest string in a PHP array
- PHP – Get the string length using mb_strlen()
- How to apply Substring() for fields in MySQL to get part of string?
- C# Program to remove the end part of a string
- How to cut part of a string with a MySQL query?
- How to get selected option using Selenium WebDriver with Java?
- How to get selected option using Selenium WebDriver with Python?