0

結局のところ、私は私の英語で申し訳ありません。

PHPでスクリプトを書いているときに小さな問題が発生しました。

アイデアは、テキストの行ごとに配列を作成し、4 番目の値をステータスを表す文字列に置き換えることです。

2022,33422,0,1,0,22などのテキスト行があります

1 行では配列を作成できますが、複数行では予期しない結果が生じます。

例:

2022,33422,0,1,0,22

2024,3232,01,1,04,298762

        $myArray = explode(',', $uploadServer);
        $status = array(0  => "Unprocessed",
                 1  => "Processing",
                 2  => "Download aborted because the file became too big.",
                 3  => "Download aborted because the file downloaded too long.",
                 4  => "Download finished. Uploading to RapidShare.",
                 5  => "Upload to RapidShare finished. Job finished.",
                 7  => "Upload failed 3 times for unknown reasons. Job aborted.",
                 8  => "Upload failed because the file is black listed.",
                 9  => "Download failed for unknown reasons.",
                 11 => "Enqueued for later processing because this account already downloads 5 files at the same time.");



        foreach ($myArray as $valor) {
              if(array_key_exists($valor[3],$status)) {

                    return $passer[] = $status[$valor[3]];

              } else {

                    return FALSE;

              }
        }

$myArrayの結果は

Array
(
    [0] => 2022
    [1] => 33422
    [2] => 0
    [3] => 1
    [4] => 0
    [5] => 22
)

しかし、私はこの最終的な配列が必要です

Array
(
[0]=>array(
          [0] => 2022
          [1] => 33422
          [2] => 0
          [3] => Processing
          [4] => 0
          [5] => 22
          )

[1]=>array(
           [0] => 2022
           [1] => 33422
           [2] => 0
           [3] => Processing
           [4] => 0
           [5] => 22
          )
)

何か案が?ありがとう

4

2 に答える 2

0

UPDATE :したがって、改行を含む文字列があります。この改行は非表示文字 (\n) です。まず、改行ごとに文字列を分割します。次に、この配列をループします。コンマごとに文字列を分割し、インデックス 3 で値を変更します。

$myArray = explode("\n", $uploadServer);

$status = array(0  => "Unprocessed",
             1  => "Processing",
             2  => "Download aborted because the file became too big.",
             3  => "Download aborted because the file downloaded too long.",
             4  => "Download finished. Uploading to RapidShare.",
             5  => "Upload to RapidShare finished. Job finished.",
             7  => "Upload failed 3 times for unknown reasons. Job aborted.",
             8  => "Upload failed because the file is black listed.",
             9  => "Download failed for unknown reasons.",
             11 => "Enqueued for later processing because this account already downloads 5 files at the same time.");

$passer = array(); //create array to fill
foreach( $myArray as $valor ) { //loop through lines
   if( !empty($valor) ) { // check for empty line
     $tmp = explode(',', $valor);  //make array of strings
     if(array_key_exists($tmp[3],$status)) {  //check value [3]
       $tmp[3] = $status[$tmp[3]];
     }     
     $passer[] = $tmp;   //append array to parent array
  } 
}
于 2012-09-20T17:53:52.267 に答える
0

私があなたを正しく理解しているなら、あなたは解決策を考えすぎています.

   foreach ($myArray as $valor) { 
          if(isset($status[$valor[3]])) {  # this checks if there is a status with that index/key
                 return $passer[] = $status[$valor[3]]; 
           } else { 
                 return FALSE; 
           } 
    } 
于 2012-09-20T17:47:25.883 に答える