preg_match能破吗? /<(\w+)>/ $match[0] 中的空结果
Can preg_match be broken? /<(\w+)>/ empty result in $match[0]
这是我的两行代码:
preg_match('/<(\w+)>/', "<word>", $match);
var_export($match);
并且输出:
array (
0 => '',
1 => 'word',
)
为什么 $match[0]
应该包含整个匹配的字符串却为空?
谢谢!
zerkms 的回复:
"because in html anything enclosed in < is treated as a tag. Check the page contents not the rendering."
编辑:
永远记住在 html 中呈现之前正确编码您的内容:
preg_match('/<(\w+)>/', "<word>", $match);
htmlentities( var_export($match) );
这是一个非常重要的安全问题。
这是我的两行代码:
preg_match('/<(\w+)>/', "<word>", $match);
var_export($match);
并且输出:
array (
0 => '',
1 => 'word',
)
为什么 $match[0]
应该包含整个匹配的字符串却为空?
谢谢!
zerkms 的回复:
"because in html anything enclosed in < is treated as a tag. Check the page contents not the rendering."
编辑:
永远记住在 html 中呈现之前正确编码您的内容:
preg_match('/<(\w+)>/', "<word>", $match);
htmlentities( var_export($match) );
这是一个非常重要的安全问题。