太长的标题要截断?如何分别全角和半角以避免乱码_PHP
作 者: lemann(lemann)
function ChgTitle($title)
{
$length = 46;
if (strlen($title)>$length) {
$temp = 0;
for($i=0; $i$length; $i++)
if (ord($title[$i]) > 128)
$temp++;
if ($temp%2 == 0)
$title = substr($title,0,$length)."...";
else
$title = substr($title,0,$length+1)."...";
}
return $title;
}
原理就是截断一个字符,看看其ascII码是不是大于128,如果是,说明截断的是一个全角汉字,那么就退后一个截断。用$length控制长度
备注:循环判断字符串里面的 >128
的字符个数,如果半角字符为偶数,则表示位置刚好为整个汉字,如果为奇数,则为半个汉字,需要取下一个字

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



Java is a very popular programming language and many projects are written in Java. However, when we encounter "Encoding and Decoding Errors" during the development process, we may feel confused and confused. In this article, we will introduce the causes of Java encoding and decoding errors, how to solve and avoid these errors. What is a codec error? During Java development, we often need to process text and files. However, different texts and files may make

JavaFX is a user interface framework for the Java platform, similar to Swing, but more modern and flexible. However, you may encounter some view errors when using it. This article will introduce how to deal with and avoid these errors. 1. Types of JavaFX view errors When using JavaFX, you may encounter the following view errors: NullPointerException This is one of the most common errors and usually occurs when trying to access an uninitialized or non-existent object. This may

With the widespread application of Java, JDBC errors often occur when Java programs connect to databases. JDBC (JavaDatabaseConnectivity) is a programming interface in Java used to connect to a database. Therefore, a JDBC error is an error encountered when a Java program interacts with a database. Here are some of the most common JDBC errors and how to solve and avoid them. ClassNotFoundException This is the most common JDBC

Use Java's String.length() function to get the length of a string. In Java programming, string is a very common data type. We often need to get the length of a string, that is, the number of characters in the string. In Java, we can use the length() function of the String class to get the length of a string. Here is a simple example code: publicclassStringLengthExample{publ

1. Delete text When you click the text with the left mouse button, many neatly arranged white squares will appear around the text, which means that the [text/shape/graphic] has been selected. Once selected, the text can be easily deleted by simply pressing the [Delete] key on the keyboard. 2. The text or shape cannot be selected. After left-clicking [Text/Shape/Graph], the [Selected State] in step 1 does not appear. There are many reasons for this kind of problem. Take the master as an example, click the menu [View] on the screen, and find [Slide Master] in [Master View]. 3. In the master view, click on the left navigation page. After finding the [text/shape/graphic] that needs to be deleted, still click the left mouse button. After selecting, press [Delete] on the keyboard to delete.

In PHP language development, we often encounter infinite loops, which will execute certain codes without limit, causing the program to crash or even the server to crash. This article will introduce some methods to avoid falling into infinite loops and help developers better solve this problem. 1. Avoid infinite recursive calls in a loop. When a function or method is called in a loop, if the function or method contains a loop statement, an infinite recursive call will be formed, causing the program to crash. To avoid this from happening, you can add a

Title is the meaning that defines the title of the web page. It is located within the tag and is the text displayed in the title bar of the browser. Title is very important for the search engine optimization and user experience of the web page. When writing HTML web pages, you should pay attention to using relevant keywords and attractive descriptions to define the title element to attract more users to click and browse.

What are the employment prospects of clinical pharmacy at Harbin Medical University? Although the national employment situation is not optimistic, pharmaceutical graduates still have good employment prospects. Overall, the supply of pharmaceutical graduates is less than the demand. Pharmaceutical companies and pharmaceutical factories are the main channels for absorbing such graduates. The demand for talents in the pharmaceutical industry is also growing steadily. According to reports, in recent years, the supply-demand ratio for graduate students in majors such as pharmaceutical preparations and natural medicinal chemistry has even reached 1:10. Employment direction of clinical pharmacy major: After graduation, students majoring in clinical medicine can engage in medical treatment, prevention, medical research, etc. in medical and health units, medical research and other departments. Employment positions: Medical representative, pharmaceutical sales representative, sales representative, sales manager, regional sales manager, investment manager, product manager, product specialist, nurse
