PHP : curl 通过正则表达式获取隐藏输入的值

PHP : curl get the value of hidden input by regex

如何获取 curl 响应中隐藏输入的值

<input type="hidden" name="csrf_token" value="b93779b0fd991381de4b67d60a2c4cd948ad1dc9" />

我试过了

  $rets = curl_exec($ch);
if (preg_match("/csrf_token/", $rets, $spoof)){
 print_r($spoof);
 // here it found it but can't get the value
}

我试过这个

 if(preg_match("/name=\"csrf_token\" value='([a-zA-z0-9]{32})'/", $rets, $spoof)) 

  //empty respown

    {

那么,我该怎么做才能解决这个问题?

我想您几乎已经掌握了它,但是示例中的值在双引号之间,而您的正则表达式期望它在单引号中。 试试这个:

if (preg_match("/name=\"csrf_token\" value=\"([a-zA-z0-9]{32})\"/", $rets, $spoof))