我有一个在PHP中运行的简单正则表达式,并且由于某种原因它不能使用左括号。参见:
$str = 'sdfsf sdfs<link rel="stylesheet" id="editor-buttons-css" href="http://localhost/wordpress/wp-includes/css/editor.min.css?ver=3.6" type="text/css" media="all">sdfsd sdfsdl';
$reg = '/<link[\s\S]+eet/';
preg_match($reg, $str, $re);
print_r($re);
// outputs: Array ( [0] => );
$str = 'sdfsf sdfs<link rel="stylesheet" id="editor-buttons-css" href="http://localhost/wordpress/wp-includes/css/editor.min.css?ver=3.6" type="text/css" media="all">sdfsd sdfsdl';
$reg = '/link[\s\S]+eet/';
preg_match($reg, $str, $re);
print_r($re);
// outputs: Array ( [0] => link rel="stylesheet );
如何让正则表达式与左括号一起使用?
答案 0 :(得分:1)
实际上是输出
Array ( [0] => <link rel="stylesheet )
但浏览器解析html,试试 echo htmlspecialchars(print_r($ re,true));