Home  >  Article  >  Backend Development  >  String function substr() in php_PHP tutorial

String function substr() in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 09:05:04945browse

String function substr() in php

Syntax: string substr(string $string int $start [,int $end]), this function also intercepts by bytes (not characters), pay attention when intercepting Chinese, and the starting position of intercepting must be at the end position The left side of , that is, always intercepted from left to right.
$str="Hello world!";
echo substr($str,3),"
";//The result is lo world!
echo substr($str,3,8),"
";//result lo wo
echo substr($str,-6),"
";//At this time, the second parameter is a negative number, which means intercepting from the sixth position from the bottom, and the result is world
echo substr($str,-6,-3),"
";//When the third parameter is a negative number, it represents the intercepted length, and the result is wor

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1070924.htmlTechArticleString function substr() in php Syntax: string substr(string $string int $start [,int $end ]), this function also intercepts by bytes (not characters), please pay attention when intercepting Chinese,...
Statement:
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