Home  >  Article  >  Database  >  MySQL和PHP中的substr

MySQL和PHP中的substr

WBOY
WBOYOriginal
2016-06-07 16:52:561134browse

substr:字符串截取函数。substr($str,$start,$end)MySQL中的substr函数中如要从第一个字符开始截取,则第一个参数应该为1;PHP中

substr:字符串截取函数。substr($str,$start,$end)

MySQL中的substr函数中如要从第一个字符开始截取,则第一个参数应该为1;

PHP中的substr函数中如要从第一个字符开始截取,则第一个参数应该为0;

注意,MySQL 5.x才开始支持substr,如果MySQL是4.x,则可以使用left($str,$length)

mysql 5.x => substr("abc",1,1)=a

mysql 4.x => left("abc",1)=a

PHP => substr("abc",0,1)=a

PS:查看MySQL版本:select VERSION()

select SUBSTRING(cpcode,2) from T_PROVINCE_MATERIAL where province_id=5

mid也行的

还有right(),left(),都可以,分别是从右边取和从左边取 

linux

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