search
HomeComputer TutorialsComputer KnowledgeUse PHP to output part of the text in the database

Use PHP to output part of the text in the database

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 "

  • 《".$name."》Price:".$price."ISBN:".$isbn."
  • "; //Output data

    }

    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!

    Statement
    This article is reproduced at:Excel办公网. If there is any infringement, please contact admin@php.cn delete
    How to Remove the SecureBootEncodeUEFI.exe Trojan?How to Remove the SecureBootEncodeUEFI.exe Trojan?Apr 13, 2025 am 12:50 AM

    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.

    Fix: Sysdll_win64_retail.dll Missing or Not Found Error - MiniToolFix: Sysdll_win64_retail.dll Missing or Not Found Error - MiniToolApr 13, 2025 am 12:48 AM

    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

    Is Core Isolation Blocked by ew_usbccgpfilter.sys? Here Are Fixes!Is Core Isolation Blocked by ew_usbccgpfilter.sys? Here Are Fixes!Apr 13, 2025 am 12:47 AM

    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.

    How to Remove Options from the Ctrl   Alt   Del Screen?How to Remove Options from the Ctrl Alt Del Screen?Apr 13, 2025 am 12:46 AM

    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

    How to Remove Virus:Win32/Grenam.VA!MSR? Here Is a Guide!How to Remove Virus:Win32/Grenam.VA!MSR? Here Is a Guide!Apr 13, 2025 am 12:45 AM

    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.

    How to Save a Website as a Desktop App?How to Save a Website as a Desktop App?Apr 13, 2025 am 12:44 AM

    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

    A Full Guide to Fixing the Windows Update Error 0x00000000A Full Guide to Fixing the Windows Update Error 0x00000000Apr 13, 2025 am 12:43 AM

    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.

    How to Fix FileType Selected Not Supported by This AppHow to Fix FileType Selected Not Supported by This AppApr 13, 2025 am 12:41 AM

    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.

    See all articles

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    AI Hentai Generator

    AI Hentai Generator

    Generate AI Hentai for free.

    Hot Article

    R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
    3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
    R.E.P.O. Best Graphic Settings
    3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
    R.E.P.O. How to Fix Audio if You Can't Hear Anyone
    3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
    WWE 2K25: How To Unlock Everything In MyRise
    4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

    Hot Tools

    MinGW - Minimalist GNU for Windows

    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

    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

    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

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    Dreamweaver Mac version

    Dreamweaver Mac version

    Visual web development tools