Summary of PHP's string operations in 4-----PHP. Summary of PHP's string operations 4-----php 1. the string connection string is connected by a half-width period. two or more strings can be connected into one string. Summary of PHP's string operations in 4-----PHP
1. the string connection string is connected by a half-width period (.). two or more strings can be connected to one character string. 2. the trim () function is provided in PHP to remove leading and trailing spaces and special characters from the string. the ltrim () function removes leading spaces and special characters from the string, the rtrim () function removes spaces and special characters on the right of the string.
'; // Remove all special characters echo trim ($ str, "\ r (::)"). ''; // remove the specified special character echo ltrim ($ str," \ r "). ''; // remove the special character echo rtrim ($ str," @ _ @ ") on the left ,"@_@"). ''; // remove the special characters specified on the right?>
3. there are two types of escape and Restoration: manually escaping, restoring string data, and automatically escaping and restoring string data. Manually escape, but you only need to add the backslash "\". The following describes the automatic escape function: addslashes (string) is used to add \ to the escape character in the string \, the addcslashes (string charlist) function is used to escape the characters specified in the string. stripslashes () is used to restore the strings escaped by the preceding two functions.
'; Echo' $ str1 character string before escape :'. $ str1. ''; echo '$ c escape a specific string :'. $ c. ''; $ B = stripcslashes ($ str1); echo '$ B restored string :'. $ B. ''; echo '$ :'. $. ''; echo'
';?>
4. obtain the string length, intercept the string, and compare the string.
'; // String length echo substr ($ str2, 0 ). ''; // capture all length strings echo substr ($ str2, 4, 10) from 0 ). ''; // truncates a string from the fourth position, including the fourth position. the position is echo substr ($ str2,-) starting from subscript 0 ). ''; // it is intercepted from the last and fourth positions, and does not contain the fourth position echo substr ($ str2, 0,-4 ). ''; // It is truncated from the 0th position until the last fourth digit. it contains the fourth character. // Two comparison string functions: strcmp (case sensitive) and strcasecmp (case insensitive ); strncmp (compare the first few strings in the two strings); // strstr (query string, from the first position of the string to the end of the string ); strchr (retrieves a string from the position in the back order of the string, opposite to the former); // substr_count (retrieves the number of times a specific string appears in a string) // replace the function: str_ireplace (search, replace, subject, int & count) searches for a string and then replaces it. search represents the string to be replaced, replace indicates the value to be replaced // subject indicates the entire string, and count indicates how many times the replacement task is executed. This function is case insensitive, use the str_replace function // to replace the string between start and length with the replace echo function: substr_replace (string, replace, start, length'
';?>
5. format the string
'; Echo number_format ($ num, 2 ). ''; echo number_format ($ num, 2 ,',','. '). ''; // Split string $ str3 = 'php programming Dictionary @ NET programming Dictionary @ ASP Programming Dictionary @ JSP programming Dictionary '; $ str_array = explode ('@', $ str3); echo 'split string: '; print_r ($ str_array); echo ''; // synthesize string echo 'synthesize string function :'; echo implode ("synthesize", $ str_array ). '';?>
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.
Character 1. the string connection string is connected by a half-width period. two or more strings can be connected to one character string ....