Home  >  Article  >  Backend Development  >  php正则表达式婚配疑问

php正则表达式婚配疑问

WBOY
WBOYOriginal
2016-06-13 13:15:38740browse

php正则表达式匹配疑问。

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->$data = "<meta http-equiv="Content-Type" content="text/html; charset=utf-8">aaa/r/naaaaaaaaaaaa"; 

preg_match_all('/<meta>]*charset=([a-zA-Z0-9]*[\-]*[0-9]*)/', $data, $meta);
var_dump($meta);

为什么打印出来是:
array
  0 => 
  array
  0 => string '   1 => 
  array
  0 => string 'utf-8' (length=4)

第二个匹配到utf-8是怎么匹配的?
不是只能匹配第一个吗?

------解决方案--------------------
探讨
PHP code
$data = "aaa/r/naaaaaaaaaaaa";

preg_match_all('/]*charset=([a-zA-Z0-9]*[\-]*[0-9]*)/', $data, $meta);
var_dump($……
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