Home > Backend Development > PHP Tutorial > 怎么获取六组字符串的第一个数字?

怎么获取六组字符串的第一个数字?

WBOY
Release: 2016-06-23 13:04:07
Original
1122 people have browsed it

4wt667KNXI

3J8fnObHjG

XZKB9rnvZU

Rx1VJu8sx5

MiAo8FaCOx

JB2RC2oFnq

上面六组字符串,是随机变化的,现在我想获取这六组字符串的第一个数字,如上面的六组我想最后得到:439182,请问应该怎么写代码?


回复讨论(解决方案)

$s = <<<TXT4wt667KNXI3J8fnObHjGXZKB9rnvZURx1VJu8sx5MiAo8FaCOxJB2RC2oFnqTXT;$arr = preg_split('/[\s]+/s', $s);$str = '';foreach($arr as $v){	preg_match('/\d/', $v, $m);	$str .= $m[0];}echo $str;
Copy after login

$s =<<< TXT4wt667KNXI3J8fnObHjGXZKB9rnvZURx1VJu8sx5MiAo8FaCOxJB2RC2oFnqTXT;preg_match_all('/(\d+?).*$/m', $s, $m);echo join('', $m[1]);
Copy after login
439182

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