我正在使用以下代码使用 PHP cURL 获取远程内容
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://example.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
echo $output;
此代码返回全部内容但我只想以以下格式打印所有样式表。
<link rel="stylesheet" href="http://www.example.com/css/style1.css">
<link rel="stylesheet" href="http://www.example.com/css/style2.css">
如何使用 str.replace() 过滤内容以仅获取带有 cURL 的样式表?