Home > Backend Development > PHP Tutorial > 正则如何匹配“102 97%”,得到array([0]=>102,[1]=>97%)的结果?

正则如何匹配“102 97%”,得到array([0]=>102,[1]=>97%)的结果?

WBOY
Release: 2016-06-06 20:35:16
Original
1046 people have browsed it

preg_match('/\S+/', $v, $output);
print_r($output);
得到是array([0]=>102)的结果,如何得到array([0]=>102,[1]=>97%)的结果?

回复内容:

preg_match('/\S+/', $v, $output);
print_r($output);
得到是array([0]=>102)的结果,如何得到array([0]=>102,[1]=>97%)的结果?

<code>preg_match_all('/\S+/',$a,$match);
var_dump($match);

/*
array (size=1)
  0 => 
    array (size=2)
      0 => string '102' (length=3)
      1 => string '97%' (length=3)
*/
</code>
Copy after login

list($first,$second) = explode(' ',$str);

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