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

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

WBOY
WBOYOriginal
2016-06-06 20:35:161042browse

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>

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

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