In many cases, the string truncation function is required. it is not enough because of the encoding problem between gb2312 and UTF-8, the following are the specific implementation methods and the code extracted from some mature systems.
1. Chinese
Multiple Chinese string truncation functions in PHP. Copy the code as follows :? PhpfunctionsysSubStr ($ string, $ length, $ appendfalse) {if (strlen ($ string) $ length) {return $ string;} else {$ i0; while ($ I $ length) {$ string
The code is as
Smart Chinese characters (utf8 and gb2312)
UTF-8 encoding. a Chinese character occupies three bytes:
Php code:
Gb2312 encoding. a Chinese character occupies two bytes:
Php code: Function smarty_modifier_cntruncate ($ string, $ strlen = 20, $ etc =
1, UTF-8, GB2312 are supported by the Chinese character intercept function
Copy Code code as follows:
/*
Chinese character interception function supported by Utf-8 and gb2312
Cut_str (string, intercept length, start length, coding);
Vulnerability Analysis of an attack Tracing System (affecting customers' core network segments and sensitive monitoring information)
The device is deployed on the Intranet. the device is directly connected to the host device monitored on the
Use php to intercept a specified length. PHP language: the code used to copy string based on Chinese characters is as follows: functioncutstr ($ string, $ length, $ dot ...) {if (strlen ($ string) $ length) {return $ string ;}$ prechr (1); PHP
Some of the following PHP functions are the most commonly used project development functions of our IT dynamics, which are also more common in more projects.
1. Processing function of the request interface
Copy CodeThe code is as follows:
/**
*
One common PHP code is the post request function of curl. it is mainly used for api development on various platforms to process request interfaces. if you have multiple platforms, data must be transmitted between them, this function is absolutely
Article title: debug GCC program with GDB in Linux (2 ). Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Gdb
Most systems are currently using a static password for authentication login, but because the static password is easy to be stolen, its security can not meet the security requirements.
Dynamic password is used once a secret, use the password to
/**
* Converts a string containing full-width numeric characters, letters, spaces, or '%+-() ' characters to corresponding half-width characters
*
* @access Public
* @param string $str the string to be converted
*
*
A Chinese string truncation function of php .? Php (as the mainstream development language) functioncnSubStr (string, sublen) if (sublenstrlen (string) returnstring; s; for (i0; isublen; I ++) if (ord (stringi) 127) s. stringi. string ++
Function
Php Chinese support function php Chinese intercept string function PHP Chinese character string flip
/**
* Convert a string containing full-width numeric characters, letters, spaces, or '% +-()' to the
One is the POST request function of curl, is mainly used for the development of Platform API, the processing function of the request interface, if you have multiple platforms, to pass data between each other, use this function absolutely useful:
Chinese intercept modifier.cn_truncate.php
Copy CodeThe code is as follows:
function Smarty_modifier_cn_truncate ($string, $strlen = A, $etc = ' ... ',
$keep _first_style = False)
{
$strlen = $strlen;
$string = Trim ($string);
if (strlen ($string)
This article mainly summarizes and introduces the PHP-encapsulated string encryption and decryption functions and usage methods, which are very simple and practical, if you have any need, you can refer to the next article to summarize and introduce
Verification code function (personal understanding):
Reduce the pressure on the server (such as the 12306 verification code function);
Prevention of violent registration
Personal idea: generate N-bit random numbers in a-z,a-z,1-9
One is the post request function of curl, which is mainly used for api development on various platforms to process request interfaces. if you have multiple platforms and want to transmit data between them, this function is absolutely useful.
One is
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.