函数不会转换数组

时间:2017-03-08 23:55:04

标签: php arrays function

我想将收到的(模型)产品值转换为原始模型值,但我的功能似乎无法正常工作

现在我不确定我做错了什么

其功能function identifierToString($DEVICE_PRODUCT){

<?php


$data = file_get_contents('php://input');

$plistBegin   = '<?xml version="1.0"';
$plistEnd   = '</plist>';
$pos1 = strpos($data, $plistBegin);
$pos2 = strpos($data, $plistEnd);
$data2 = substr ($data,$pos1,$pos2-$pos1);
$xml = xml_parser_create();
xml_parse_into_struct($xml, $data2, $vs);
xml_parser_free($xml);

$UDID = "";
$CHALLENGE = "";
$DEVICE_NAME = "";
$DEVICE_PRODUCT = "";
$DEVICE_VERSION = "";
$iterator = 0;

$arrayCleaned = array();
foreach($vs as $v){
if($v['level'] == 3 && $v['type'] == 'complete'){
$arrayCleaned[]= $v;
}
$iterator++;
}

$data = "";
$iterator = 0;

foreach($arrayCleaned as $elem){

$data .= "\n==".$elem['tag']." -> ".$elem['value']."<br/>";

switch ($elem['value']) {

case "CHALLENGE":

$CHALLENGE = $arrayCleaned[$iterator+1]['value'];

break;

case "NAME":

$DEVICE_NAME = $arrayCleaned[$iterator+1]['value'];

break;

case "PRODUCT":

$DEVICE_PRODUCT = $arrayCleaned[$iterator+1]['value'];

break;

case "UDID":

$UDID = $arrayCleaned[$iterator+1]['value'];

break;

case "VERSION":

$DEVICE_VERSION = $arrayCleaned[$iterator+1]['value'];

break;

}
$iterator++;
}

function identifierToString($DEVICE_PRODUCT){
    $models = array(
        "iPhone5,1" => "iPhone 5",           //iPhone 5
        "iPhone5,2" => "iPhone 5",           //iPhone 5
        "iPhone5,3" => "iPhone 5C",          //iPhone 5C
        "iPhone5,4" => "iPhone 5C",          //iPhone 5C
        "iPhone6,1" => "iPhone 5S",          //iPhone 5S
        "iPhone6,2" => "iPhone 5S",          //iPhone 5S
        "iPhone7,2" => "iPhone 6",           //iPhone 6
        "iPhone7,1" => "iPhone 6+",          //iPhone 6+
        "iPhone8,1" => "iPhone 6S",          //iPhone 6S
        "iPhone8,2" => "iPhone 6S+",         //iPhone 6S+
        "iPhone8,4" => "iPhone SE",          //iPhone SE
        "iPhone9,1" => "iPhone 7",           //iPhone 7
        "iPhone9,2" => "iPhone 7+",          //iPhone 7+
        "iPhone9,3" => "iPhone 7",           //iPhone 7
        "iPhone9,4" => "iPhone 7+",          //iPhone 7+

    );

    if(isset($models[$DEVICE_PRODUCT])){
        return $models[$DEVICE_PRODUCT];
    } else {
        return $DEVICE_PRODUCT;
    }

}

$params = "UDID=".$UDID."&CHALLENGE=".$CHALLENGE."&DEVICE_NAME=".$DEVICE_NAME."&DEVICE_PRODUCT=".$DEVICE_PRODUCT."&DEVICE_VERSION=".$DEVICE_VERSION;

header('Location: https://vezuure.me/udid?'.$params);

?>

当数据被重定向到下一页时,我仍然会收到未转换的值

1 个答案:

答案 0 :(得分:0)

我真的不明白有这个功能。试图清理一些spaghettis ....

$arrayCleaned = array();
foreach ($vs as $key => $v) {
    if ($v['level'] == 3 && $v['type'] == 'complete') {
        $arrayCleaned[] = $v;
    }
}

$data = "";
foreach ($arrayCleaned as $key => $elem) {
    $data .= "\n==" . $elem['tag'] . " -> " . $elem['value'] . "<br/>";
    switch ($elem['value']) {
        case "CHALLENGE":
            $CHALLENGE = $arrayCleaned[$key + 1]['value'];
            break;

        case "NAME":
            $DEVICE_NAME = $arrayCleaned[$key + 1]['value'];
            break;

        case "PRODUCT":
            $DEVICE_PRODUCT = $arrayCleaned[$key + 1]['value'];
            break;

        case "UDID":
            $UDID = $arrayCleaned[$key + 1]['value'];
            break;

        case "VERSION":
            $DEVICE_VERSION = $arrayCleaned[$key + 1]['value'];
            break;
    }
}

$models = array(
    "iPhone5,1" => "iPhone 5", //iPhone 5
    "iPhone5,2" => "iPhone 5", //iPhone 5
    "iPhone5,3" => "iPhone 5C", //iPhone 5C
    "iPhone5,4" => "iPhone 5C", //iPhone 5C
    "iPhone6,1" => "iPhone 5S", //iPhone 5S
    "iPhone6,2" => "iPhone 5S", //iPhone 5S
    "iPhone7,2" => "iPhone 6", //iPhone 6
    "iPhone7,1" => "iPhone 6+", //iPhone 6+
    "iPhone8,1" => "iPhone 6S", //iPhone 6S
    "iPhone8,2" => "iPhone 6S+", //iPhone 6S+
    "iPhone8,4" => "iPhone SE", //iPhone SE
    "iPhone9,1" => "iPhone 7", //iPhone 7
    "iPhone9,2" => "iPhone 7+", //iPhone 7+
    "iPhone9,3" => "iPhone 7", //iPhone 7
    "iPhone9,4" => "iPhone 7+", //iPhone 7+
);

$result = (isset($models[$DEVICE_PRODUCT])) ? $models[$DEVICE_PRODUCT] : $models;

$params = "UDID=" . $UDID . "&CHALLENGE=" . $CHALLENGE . "&DEVICE_NAME=" . $DEVICE_NAME . "&DEVICE_PRODUCT=" . $result . "&DEVICE_VERSION=" . $DEVICE_VERSION;