Collection of methods for intercepting php, js, and css strings _ javascript skills

Source: Internet
Author: User
This article mainly introduces php, js, and css string interception methods. In fact, there is no technical content, that is, record it, so that you can easily review and consolidate it yourself, I hope it will be helpful to you, but it may be useless.
The first is the PHP version.

The Code is as follows:


<? Php echo mb_strimwidth ("here is the content", "...", "UTF-8");?>

In fact, only one mb_strimwidth function can be used. The description of this function is as follows:
Mb_strimwidth-get the string truncated by the specified width
String mb_strimwidth (string $ str, int $ start, int $ width [, string $ trimmarker = "" [, string $ encoding = mb_internal_encoding ()])
Parameter description:
$ Str is the string to be truncated (that is, the original string, the output string)
$ Start is truncated starting from the nth character. The default value is 0.
$ Width the width to be trimmed
$ After the trimmarker is intercepted, the content added to the end of the string (commonly referred to as... indicates that the content is omitted). By default, I am empty.
$ Encoding: this parameter is very important. If the string is Chinese, you must add it. Otherwise .... You can see "��". I haven't carefully read this function before. In the wordpress topic, because I want to display a short section of the article, there will be garbled characters at the end, I don't know why for a long time. In addition, this parameter should be consistent with the webpage encoding format. In my personal test, the webpage encoding is UTF-8, and the Chinese character is shit when the parameter is written as gbk .. (Could you please explain)
This is the case with the php version. Sometimes we think it is a problem with the php language, but we did not study it carefully.

Js version:

There is almost * no difference between the substring () and substr () methods,
The first parameter of the substring () method is required. It is the position of the first character of the substring to be extracted in the string. The second parameter is optional, it is the position of the last character of the substring to be extracted in stringObject, which is one more character. It is not included by default and ends at the end of the string.
The first parameter of substr () is required. The starting subscript of the substring to be extracted. It must be a numerical value. If it is a negative number, this parameter declares the position starting from the end of the string. That is to say,-1 refers to the last character in the string,-2 refers to the second to last character, and so on. The second parameter is optional. The number of characters in the substring. It must be a numerical value. If this parameter is omitted, the string from the start position of the stringObject to the end is returned.
Example:

The Code is as follows:


Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.