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

WBOY
Release: 2016-06-13 10:04:27
Original
802 people have browsed it

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

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

Related labels:
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
Popular Tutorials
More>
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!