{ "title": "PHP函数:解析 iPhone 设备信息,并格式化输出", "description": "该 PHP 函数接收两个字符串参数,包含 iPhone 设备的详细信息,并返回一个格式化的字符串,包含串号、序列号、型号、内存、颜色、网络锁、激活状态、保修状态等信息。", "keywords": "PHP 函数, iPhone 设备信息, 解析, 格式化输出, 串号, 序列号, 型号, 内存, 颜色, 网络锁, 激活状态, 保修状态", "content": """"php\nfunction formatDeviceInfo($input1, $input2)\n{\n $result = ""\n \n // 获取参数1中的信息\n $serialNumber = getParamValue($input1, "串号:");\n $serialNumber2 = getParamValue($input1, "串号2:");\n $model = getParamValue($input1, "型号:");\n $capacity = getParamValue($input1, "容量:");\n $color = getParamValue($input1, "颜色:");\n $networkLock = getParamValue($input1, "网络锁:");\n \n // 获取参数2中的信息\n $activationStatus = getParamValue($input2, "激活状态:");\n $activationTime = getParamValue($input2, "激活时间:");\n $phoneSupport = getParamValue($input2, "电话支持:");\n $warrantyStatus = getParamValue($input2, "保修状态:");\n $warrantyRemaining = getParamValue($input2, "保修剩余:");\n $purchaseDate = getParamValue($input2, "有效购买日期:");\n $extendedWarranty = getParamValue($input2, "是否延保:");\n $loanDevice = getParamValue($input2, "借出设备:");\n $manufacturingLocation = getParamValue($input2, "设备产地:");\n $rejectedWarranty = getParamValue($input2, "拒保记录:");\n $resourceDevice = getParamValue($input2, "是否资源机:");\n $preActivated = getParamValue($input2, "是否预激活:");\n \n // 组装结果字符串\n if (!empty($serialNumber)) {\n $result .= "串号: " . $serialNumber . "\n";\n }\n if (!empty($serialNumber2)) {\n $result .= "串号2: " . $serialNumber2 . "\n";\n }\n if (!empty($model)) {\n $result .= "序列号: " . $model . "\n";\n }\n if (!empty($model)) {\n $result .= "型号: " . $model . "\n";\n }\n if (!empty($capacity)) {\n $result .= "内存: " . $capacity . "\n";\n }\n if (!empty($color)) {\n $result .= "颜色: " . $color . "\n";\n }\n if (!empty($networkLock)) {\n $result .= "网络锁: " . $networkLock . "\n";\n }\n if (!empty($model) && stripos($model, "iPhone") !== false) {\n $result .= "产品类型: iPhone\n";\n }\n if (!empty($activationStatus)) {\n $result .= "激活状态: " . $activationStatus . "\n";\n }\n if (!empty($activationTime)) {\n $result .= "激活时间: " . $activationTime . "\n";\n }\n if (!empty($phoneSupport)) {\n $result .= "电话支持: " . $phoneSupport . "\n";\n }\n if (!empty($warrantyStatus)) {\n $result .= "保修状态: " . $warrantyStatus . "\n";\n }\n if (!empty($warrantyRemaining)) {\n $result .= "保修剩余: " . $warrantyRemaining . "\n";\n }\n if (!empty($purchaseDate)) {\n $result .= "有效购买日期: " . $purchaseDate . "\n";\n }\n if (!empty($extendedWarranty)) {\n $result .= "是否延保: " . $extendedWarranty . "\n";\n }\n if (!empty($loanDevice)) {\n $result .= "借出设备: " . $loanDevice . "\n";\n }\n if (!empty($manufacturingLocation)) {\n $result .= "设备产地: " . $manufacturingLocation . "\n";\n }\n if (!empty($rejectedWarranty)) {\n $result .= "拒保记录: " . $rejectedWarranty . "\n";\n }\n if (!empty($resourceDevice)) {\n $result .= "是否资源机: " . $resourceDevice . "\n";\n }\n if (!empty($preActivated)) {\n $result .= "是否预激活: " . $preActivated . "\n";\n }\n \n return $result;\n}\n\nfunction getParamValue($input, $param)\n{\n $value = "";\n $startIndex = strpos($input, $param);\n \n if ($startIndex !== false) {\n $startIndex += strlen($param);\n $endIndex = strpos($input, "\n", $startIndex);\n if ($endIndex !== false) {\n $value = trim(substr($input, $startIndex, $endIndex - $startIndex));\n } else {\n $value = trim(substr($input, $startIndex));\n }\n }\n \n return $value;\n}\n\n$input1 = "型号: iPhone 14 Pro 256GB 金色\n序列号: MHNJQYM3PT\n串号: 357154676689981\n串号2: 357154676676384\n购买时间: 2023-06-1\n网络锁: 有锁/LOCKED";\n$input2 = "设备序号: 357154676689981\n设备型号: iPhone 14 Pro\n设备容量: 256GB\n设备颜色: 金色\n产品类型: iPhone\n激活状态: 未激活\n激活时间: 未激活\n电话支持: 未激活\n保修状态: 未激活\n保修剩余: 未激活\n有效购买日期: 已验证\n是否延保: 未激活\n借出设备: 否\n设备产地: Foxcom\n拒保记录: 无\n是否资源机: 否\n是否预激活: 否";\n\n$result = formatDeviceInfo($input1, $input2);\necho $result;\n"""


原文地址: https://www.cveoy.top/t/topic/p8nr 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录