Web Front-end
JS Tutorial
Collection of methods to intercept strings in php, js, css_javascript skills
Collection of methods to intercept strings in php, js, css_javascript skills
It may not contain much content, please don’t buy it.
The first is the PHP version.
In fact, you only need to use the mb_strimwidth function. The description of this function is as follows:
mb_strimwidth — Get a 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 (i.e. original string, output string)
$start starts intercepting characters, the default is 0
$width The width to be trimmed
$trimmarker After interception, the content added at the end of the string (commonly... means omitted), the default is empty
The $encoding parameter is very important. If the string is Chinese, it must be added. otherwise. . . . You can see the "�" thing. I haven't looked at this function carefully before. In the WordPress theme, because it needs to display a small section of the article, there are garbled characters at the end. I don't know why for a long time. In addition, this parameter should be consistent with the encoding format of the web page. During personal testing, the web page was encoded as utf-8. When the parameter was written as gbk, the Chinese characters would be shit. . (please ask for explanation)
That's it for the PHP version. Sometimes I think it's a problem with the PHP language, but in fact it's just that we didn't study it carefully.
js version:
substring() and substr() methods, there is *almost* no difference between the two methods,
The first parameter of the substring() method is required and is the position of the first character of the substring to be extracted in the string. The second parameter is optional and is the last character of the substring to be extracted in the stringObject. The position has one more digit, defaults to none, and reaches the end of the string.
The first parameter of substr() is required. The starting index of the substring to be extracted. Must be a numeric value. If negative, this parameter declares the position from the end of the string. That is, -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. Must be a numeric value. If this parameter is omitted, the string from the beginning to the end of stringObject is returned.
Example:
This example outputs: lo world!
Starting from the third digit of the original string to the end
This example output: lo w
Starting from the fourth digit of the original string to the seventh digit
Output: lo world!
Starting from the third position to the end
Output: lo worl
Starting from the fourth digit, intercept 7 digits.
You can see these two JS methods
http://www.w3school.com.cn/js/jsref_substring.asp
http://www.w3school.com.cn/jsref/jsref_substr.asp
The third one is CSS
CSS interception mainly uses the text-overflow attribute.
text-overflow: [ clip | ellipsis |
The default value of text-overflow is clip, that is, when the content exceeds the container, the excess text will be cut off. When the value is ellipsis, the excess text will be replaced with ellipses; you can also use a specific string to replace the excess text. Text (currently only supported by Firefox).
Example of ellipsis:
.ellipsis{
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
[copy]Reference:
http://quirksmode.org/css/user-interface/textoverflow.html
https://developer.mozilla.org/en-US/docs/Web/CSS/text-overflow
In fact, the description of css can be understood by looking at the legend on the mozilla developer website. Not much to say here.
Hot AI Tools
Undresser.AI Undress
AI-powered app for creating realistic nude photos
AI Clothes Remover
Online AI tool for removing clothes from photos.
Undress AI Tool
Undress images for free
Clothoff.io
AI clothes remover
AI Hentai Generator
Generate AI Hentai for free.
Hot Article
Hot Tools
Notepad++7.3.1
Easy-to-use and free code editor
SublimeText3 Chinese version
Chinese version, very easy to use
Zend Studio 13.0.1
Powerful PHP integrated development environment
Dreamweaver CS6
Visual web development tools
SublimeText3 Mac version
God-level code editing software (SublimeText3)
Hot Topics
1380
52
The Roles of HTML, CSS, and JavaScript: Core Responsibilities
Apr 08, 2025 pm 07:05 PM
HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.
How to use bootstrap in vue
Apr 07, 2025 pm 11:33 PM
Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.
How to write split lines on bootstrap
Apr 07, 2025 pm 03:12 PM
There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.
How to resize bootstrap
Apr 07, 2025 pm 03:18 PM
To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-
How to insert pictures on bootstrap
Apr 07, 2025 pm 03:30 PM
There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.
How to set up the framework for bootstrap
Apr 07, 2025 pm 03:27 PM
To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.
How can you prevent a class from being extended or a method from being overridden in PHP? (final keyword)
Apr 08, 2025 am 12:03 AM
In PHP, the final keyword is used to prevent classes from being inherited and methods being overwritten. 1) When marking the class as final, the class cannot be inherited. 2) When marking the method as final, the method cannot be rewritten by the subclass. Using final keywords ensures the stability and security of your code.
How to view the date of bootstrap
Apr 07, 2025 pm 03:03 PM
Answer: You can use the date picker component of Bootstrap to view dates in the page. Steps: Introduce the Bootstrap framework. Create a date selector input box in HTML. Bootstrap will automatically add styles to the selector. Use JavaScript to get the selected date.


