php正则表达

WBOY
Release: 2016-06-23 14:03:33
Original
743 people have browsed it

怎么写一个正则,同时匹配两种标签
$pattern="#(\)#U";
$pattern="#(\.*\)#U";
像上面两,分别匹配了input和select。如何把它们合并成一个,只要满足其中一种都行。因为需要按照标签的顺序输出,所以不能分成两次来匹配


回复讨论(解决方案)

$str = '<input type="text" name="lname" />';  $str .= '<select><option value ="volvo">Volvo</option><option value ="saab">Saab</option><option value="opel">Opel</option><option value="audi">Audi</option></select>';preg_match_all("#((\<input.*\>)|(\<select.*\>.*\<\/select\>))#U",$str,$out);var_dump($out);
Copy after login


这样可否?

正则里有或‘|’这个操作符

PHP code?123456$str = '';  $str .= '

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!