Home >Backend Development >PHP Tutorial >提取字符串中数字解决办法

提取字符串中数字解决办法

WBOY
WBOYOriginal
2016-06-13 10:04:27838browse

提取字符串中数字
现在有
$z="note1"
怎么用正则取出其中的1
让$z="1"
此时$z是str
怎么把它变成数字类型呢

------解决方案--------------------
$z="note1";
preg_match('/([0-9]+)/', $z,$marray);
$z=$marray[1];
$z=intval($z);//多余的,php是弱类型

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