简体   繁体   English

使用特定模式的正则表达式查找值

[英]regex-find values with specific pattern

I want to find specific values, from an string. 我想从字符串中找到特定的值。

I have a string like: 我有一个像这样的字符串:

$str = '
[mytips id="101" zcode="Volvo"]
[mytips id="321" zcode="BMW"]
[mytips id="423" zcode="Toyota"]
';

I need to get all the values of attribute zcode. 我需要获取属性zcode的所有值。 So I can get a list/array like: 所以我可以得到一个列表/数组,如:

Array(
[0] => Volvo
[1] => BMW
[2] => Toyota

Thanks in advance 提前致谢

You can use regex in preg_match_all() at php. 您可以在php的preg_match_all()中使用正则表达式。

preg_match_all('/zcode\s*=\s*"([^"]*)"/', $str, $m);
print_r($m[1]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM