简体   繁体   中英

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. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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