[PHP][学习笔记][CURL]监测设备运行情况小demo
1.curl获取的web content 不能直接echo到页面,会造成js各种错误
2.想办法处理字符串的截取、拼接
2.1.裁剪html返回的字符串
function cutStringFrom($mainStr,$toCunSampleStr){ // 保存要被裁剪的字符串 $cuttedStr = $mainStr; // 要裁剪的字符串样本 $targetString = $toCunSampleStr; // 先找到 样本字符串 位置 $index = strpos($cuttedStr,$targetString); // 样本字符串长度 $targetStringLength = strlen($targetString); // 开始截断 $cuttedStr = substr($cuttedStr,$index + $targetStringLength); // 返回截断后结果 return $cuttedStr; }
2.2.从字符串的最前面两个双引号之前取出数值
function getStringBetweenDoubleMarks($mainStr){ // 保存要查找内容的原字符串 $cuttedStr = $mainStr; // 找到第一个" $strRemovedFirstMark = cutStringFrom($cuttedStr,"\""); $indexNextMark = strpos($strRemovedFirstMark,"\""); $valueBetweenDoubuleMark = substr($strRemovedFirstMark,0,$indexNextMark); return $valueBetweenDoubuleMark; }
2.3获取设备呼叫统计参数
function getCallSummary($html){ $htmlContent = $html; $propertyValue = array(); $propertyName = array("g_WebPort","kIpAddress","sysName","CALLTIME","CALLTOTALNUMBER","IPCALLTOTALNUMBER","IPCALLTOTALTIME","PERCENT_IP_CALLS","ISDNCALLTOTALNUMBER","ISDNCALLTOTALTIME","PERCENT_ISDN_CALLS"); foreach ($propertyName as $value){ $htmlContent = cutStringFrom($htmlContent,$value); $propertyValue[] = getStringBetweenDoubleMarks($htmlContent); } return $propertyValue; }
浙公网安备 33010602011771号