How to use substr function in PHP?

Guanhui
Release: 2023-03-03 15:58:01
Original
4422 people have browsed it

The function of the substr function in PHP is to return a part of the string. Its syntax is "substr(string,start,length)". Its parameter string indicates that part of the string is returned, and the parameter start indicates that it is in the string. Where to start, the parameter length indicates the interception length.

How to use substr function in PHP?

Usage examples

"; echo substr("Hello world",1)."
"; echo substr("Hello world",3)."
"; echo substr("Hello world",7)."
"; echo substr("Hello world",-1)."
"; echo substr("Hello world",-10)."
"; echo substr("Hello world",-8)."
"; echo substr("Hello world",-4)."
"; ?>
Copy after login
"; echo substr("Hello world",1,8)."
"; echo substr("Hello world",0,5)."
"; echo substr("Hello world",6,6)."
"; echo substr("Hello world",0,-1)."
"; echo substr("Hello world",-10,-2)."
"; echo substr("Hello world",0,-6)."
"; echo substr("Hello world",-2-3)."
"; ?>
Copy after login

Recommended tutorial: "PHP"

The above is the detailed content of How to use substr function in PHP?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!