Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何提取与preg_match匹配的字符串_Php_Preg Match - Fatal编程技术网

Php 如何提取与preg_match匹配的字符串

Php 如何提取与preg_match匹配的字符串,php,preg-match,Php,Preg Match,我从html文件中提取类名,每一行包含类名,如 </div><div id='css-11_uss_pss_sss-__i__' class='sss'> <div class="sss-top"> </div><div id='css-42_aap-8' class='css'> <div class="sss-top"> 我需要从不同的线路中提取“uss_pss_sss”和“aap-8” 我

我从html文件中提取类名,每一行包含类名,如

      </div><div id='css-11_uss_pss_sss-__i__' class='sss'> <div class="sss-top">
      </div><div id='css-42_aap-8' class='css'> <div class="sss-top">

我需要从不同的线路中提取“uss_pss_sss”和“aap-8”

我尝试这段代码,它提取第一个条件

            preg_match("/(?<=_).*?(?=-__i__)/", $buffer, $match);

preg_match(“/(?由于两个原因,您不能:

1)
aap-8
不能是您的模式的结果,因为它后面没有您的前瞻性断言中指出的
-\uu i\uu

2) preg_match函数只提供第一个匹配,必须改用preg_match_all

您可以通过以下方法解决这两个问题:

preg_match_all("/(?<=_).*?(?=-(?:__i__)?|')/", $buffer, $matches);
print_r($matches);

preg\u match\u all(“/”?我真的很感谢你这么快就回答了我的问题,你能给我提供一些模式来获得第二个条件吗。我不知道如何匹配第二个条件。。