PHP 和 cURL 从标头中提取变量


PHP and cURL extract variable from header

    $response = curl_exec($ch);
    preg_match_all('/^Location:(.*)$/mi', $response, $matches);
    curl_close($ch);

使用此脚本,我得到输出: http://website.com/632383970568166e82391f.png

我需要提取 ID,即 abcdef 并在另一个调用中使用它。我该怎么做?

使用正则表达式或执行以下操作:

$url = "http://subdomain.website.com/something/folder1/folder2/folder3/folder4/folder5/20385425_632383970568166e82391f.png";
$urlParts = explode('/', $url)
$imgFileParts = explode('_', $urlParts[(count($urlParts) - 1)]);
$imgId = $imgFileParts[0];

简单的正则表达式

$re = "/''S+''/([''S]+)_/"; 
$str = "http://subdomain.website.com/something/folder1/folder2/folder3/folder4/folder5/20385425_632383970568166e82391f.png"; 
preg_match($re, $str, $matches);