String is one of the commonly used data types in PHP and is often used in our daily PHP development. A string is a sequence of characters composed of numbers, letters, and underscores. It is a data type that represents text in programming languages. Strings are stored like character arrays, so each individual element of a string can be extracted.
1. mb_strimwidth string interception function uses & UTF8 encoding understanding
<?php header("Content-type:text/html;charset=utf-8"); echo mb_strwidth("6", "UTF-8") . '<br />'; echo mb_strwidth("A", "UTF-8") . '<br />'; echo mb_strwidth("a", "UTF-8") . '<br />'; echo mb_strwidth("月", "UTF-8") . '<br />'; echo mb_strwidth("6月9日OUR系统升级通知", "UTF-8") . '<br />'; echo mb_strimwidth("6月9日OUR系统升级通知", 0, 10, '...') .'<br />'; echo mb_strimwidth("6月9日OUR系统升级通知", 0, 10, '...', "UTF-8") .'<br />'; echo mb_strimwidth("6月9日OUR系统升级通知", 0, 10, '......', "UTF-8") .'<br />'; echo mb_strimwidth("6月9日OUR系统升级通知", 0, 10, '', "UTF-8") .'<br />'; ?>
This function requires the system to load mb (multi-byte ) extension, the $trimmarker parameter will affect the result, and its length is also included in the result.
Recommended related articles:
PHP string encryption enhanced version
PHP string definition Methods and their differences
How to convert PHP strings into arrays
The above is the detailed content of Strings in PHP explained in detail. For more information, please follow other related articles on the PHP Chinese website!