php - 从 html 格式 PHP 中的 Curl 响应中获取数据
问题描述
我正在使用 Curl 更新一些记录,在发送响应请求后,我得到了 HTML 格式数据。我想检查响应,响应是什么。我的代码是:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$cacheManager = $objectManager->get('\Magento\Framework\App\CacheInterface');
$cacheManager->clean('catalog_product_' . $param);
$varnishurl = "www.exapmle.com";
$varnishcommand = "PURGE";
$productID = $param; // This is the Magento ProductID of the item you want to purge
$curl = curl_init($varnishurl);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $varnishcommand);
curl_setopt($curl, CURLOPT_HTTPHEADER, ['X-Magento-Tags-Pattern: catalog_product_'.$productID]);
$result = curl_exec($curl);
curl_close($curl);
OutPut: 我想添加条件来检查返回的内容?要么它像响应标题或正文文本一样被清除。我已经尝试通过 json 格式发送但没有运气。
解决方案
只需稍微更改我的代码,我就得到了答案。添加带标签标签以删除 HTML 标签,然后搜索所需的内容。
$data = strip_tags($result);
if(strpos($data, '200 Purged') !== false){
return 'Cache updated successfully for the Product Id '.$param;
}else{
return 'Some error occured during cache update for the Product Id '.$param;
}
推荐阅读
- sql-workbench-j - 使用 SQL Workbench/J 的多个实例
- docker-compose - Testcontainers DockerComposeContainer 与 Docker Compose 版本 v2.0.0
- r - 在 R 中绘制半监督决策树(包:SSLR)
- android - 从 AudioRecord 读取数据时出现 ERROR_BAD_VALUE
- c++ - C ++如何实现删除运算符以释放内存取决于上下文
- python - 在石榴贝叶斯网络中表示疾病和症状
- google-apps-script - Google 表格 - 在多张表格上更新相同的目标范围
- bash - 在 Bash 中具有多个条件的路径名扩展
- java - Java,在构造函数中添加和显示考试分数数组以及其他细节
- sql - 在一个主表上左连接多个表