Home  >  Article  >  Backend Development  >  获取字符串中数字的正则表达式

获取字符串中数字的正则表达式

WBOY
WBOYOriginal
2016-07-25 08:42:49996browse
  1. $patterns = "/\d+/"; //第一种
  2. //$patterns = "/\d/"; //第二种
  3. $strs="left:0px;top:202px;width:90px;height:30px";
  4. preg_match_all($patterns,$strs,$arr);
  5. print_r($arr);
  6. /***************运行结果*********************/
  7. //第一种
  8. Array
  9. (
  10. [0] => Array
  11. (
  12. [0] => 0
  13. [1] => 202
  14. [2] => 90
  15. [3] => 30
  16. )
  17. )
  18. //第二种
  19. Array
  20. (
  21. [0] => Array
  22. (
  23. [0] => 0
  24. [1] => 2
  25. [2] => 0
  26. [3] => 2
  27. [4] => 9
  28. [5] => 0
  29. [6] => 3
  30. [7] => 0
  31. )
  32. )
复制代码

正则表达式


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