How to output part of the text in the database under php
Owner, don’t listen to other people’s nonsense. Every time there are people who don’t know how to pretend to understand,
If substr is used and the number happens to be in Chinese, garbled characters will appear
Because numbers and letters count as 1 byte, and Chinese counts as 2 bytes,
substr is not cut by numbers but by bytes
you can use it
echo mb_substr('I am very happy today', 0, 5, 'utf-8');
echo mb_strcut ('I am very happy today', 0,5, 'utf-8');
The first one is output by number,
The second one is output by bytes,
The most important thing is that there will be no garbled characters
If your page is gb2312, you can change the utf-8 on the back yourself
But the first few words you want to extract from your article, if it is edited with an editor
may contain HTML, which needs to be processed separately.
Reference materials, my own space:
How PHP outputs each piece of data in the database
$link=mysql_connect("localhost","","");
MySQL_query("SET NAMES 'gbk'");
$sql = "select * from books";
$result = mysql_query($sql, $link); //Execute query statement
while ($bookInfo = mysql_fetch_array($result)){ //Return the query results to the array
$name = $bookInfo["name"]; //Remove data from the array
$price = $bookInfo["price"];
$isbn = $bookInfo["ISBN"];
echo "
}
mysql_free_result($result);
mysql_close($link);
?>
Do you understand? Use while to output all data.
How does php get the value from the database and output it on the html page
Use PHP to determine whether the query array is empty. If it is not empty, it will assign a value to the html and control whether to display the image.
$sql = "select * from '_goods_attr' where 'attr_value'=' '"; PHP query, $res=mysql_query($sql); PHP processing, $arr = mysql_fetch_assoc($res); Convert to array, The next step is to determine whether the array is empty and assign values to the html template.
$selv=array(1,2,3,4,5); //Drop-down list value
$dbv=3;
foreach($selv as $s){
$issl='';
if($s==$dbv) $issl='selected';
$str.="";
}
echo '';
?>
The above is the detailed content of Use PHP to output part of the text in the database. For more information, please follow other related articles on the PHP Chinese website!

Some Windows 11/10 users report that they see a cmd window open up right after a Bitdefender update and it is running SecureBootEncodeUEFI.exe. This post from php.cn introduces how to remove the SecureBootEncodeUEFI.exe Trojan.

Sysdll_win64_retail.dll is a dynamic link library (DLL) file related to the FIFA 17 application. When that file gets missed or corrupted, a series of issues and errors will happen about that application. To resolve this issue, you can read this artic

Many SurfaceBook users report that they meet the “core isolation blocked by ew_usbccgpfilter.sys” issue on Windows 11/10. This post from php.cn helps to fix the annoying issue. Keep on your reading.

When you press Ctrl Alt Del on your computer, you will enter the Security Options window, where you might see Lock, Switch user, and Sign out options. Do you know that these options can be changed? This php.cn post will show you how to remove opt

Some Windows 11/10 users report that their Windows Defender has spotted a virus named Virus:Win32/Grenam.VA!MSR. But they don’t know how to remove it. This post from php.cn teaches you how to remove Virus:Win32/Grenam.VA!MSR.

When you need to visit a website frequently, it is quite troublesome to open a browser and search for it every time. Why don’t you try to save a website as an app? If you do this, you can open it as normal software. Here, php.cn offers you some usefu

Some people encountered the error code 0x00000000 on Windows 11 when they installed the latest Windows update. What should you do to cope with this unexpected error? This article on the php.cn Website will give you some clues for troubleshooting.

Are you suffering from the error message "FileType selected not supported by this app" when opening files in Teams or Excel? Now read this post from php.cn to get several useful solutions to this issue.


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

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver Mac version
Visual web development tools