Home >Backend Development >PHP Tutorial >Strings in PHP explained in detail

Strings in PHP explained in detail

墨辰丷
墨辰丷Original
2018-05-09 10:07:311715browse

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") . &#39;<br />&#39;; 
echo mb_strwidth("A", "UTF-8") . &#39;<br />&#39;;  
echo mb_strwidth("a", "UTF-8") . &#39;<br />&#39;; 
echo mb_strwidth("月", "UTF-8") . &#39;<br />&#39;; 

echo mb_strwidth("6月9日OUR系统升级通知", "UTF-8") . &#39;<br />&#39;; 

echo mb_strimwidth("6月9日OUR系统升级通知", 0, 10, &#39;...&#39;) .&#39;<br />&#39;;
echo mb_strimwidth("6月9日OUR系统升级通知", 0, 10, &#39;...&#39;, "UTF-8") .&#39;<br />&#39;;
echo mb_strimwidth("6月9日OUR系统升级通知", 0, 10, &#39;......&#39;, "UTF-8") .&#39;<br />&#39;;
echo mb_strimwidth("6月9日OUR系统升级通知", 0, 10, &#39;&#39;, "UTF-8") .&#39;<br />&#39;;

?>

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn