2016-05-30 19 views
-6

私はこのコードをjavaに入れています。これをPHPに変換したいと思います。この関数を使って、私はいくつかのデータをフォーマットし、それらをtxtファイルに書きたいと思います。PHPの書式設定テキスト

Javaのテキストクラスとして、それを処理するクラスがありますか?

public static void printAll(int n1, int n2, double[][] m, 
      String[] labs, double scaling, JTextArea outext) 
{ 
    // Some definitions for handling output formating 
    NumberFormat myFormat = NumberFormat.getNumberInstance(); 
    FieldPosition fp = new FieldPosition(NumberFormat.INTEGER_FIELD); 
    // Following suppresses e.g. comma in 1,000 = 1000 for English locale. 
    myFormat.setGroupingUsed(false); 

    int w; 
    double maxval; 
    maxval = SMALL; 

    for (int i =0; i < n1; i++) { 
     for (int j =0; j < n2; j++) { 
      // Scale up values by 'scaling' factor 
      if (m[i][j] > maxval) maxval = m[i][j]; 
     } 
    } 

    String temp = myFormat.format(maxval*scaling, 
        new StringBuffer(), fp).toString(); 
    // Output display field width of each number: extra 2 to 
    // account for possible minus sign, and 1 space. 
    w = fp.getEndIndex() - fp.getBeginIndex() + 2; 
    // System.out.println(" Output field width = " + w); 

    // In the next few lines we say how we want numbers to appear. 
    // max integer digits = max no. of digits before dec. point 
    // max fraction digits = max no. of digits following dec. point 
    // min fraction digits = min no. of digits following dec. point 
    myFormat.setMaximumIntegerDigits(w); 
    // We will set min and max nos. of digits following dec. point to 0 
    myFormat.setMaximumFractionDigits(0); 
    myFormat.setMinimumFractionDigits(0); 
    for (int i=0; i<n1; i++) 
    { 
     // First handle cols for labels, QLT, PDS, INR: 
     String myString = labs[i]; 
     myString = getSpaces(4 - myString.length()) + myString; 
      outext.append("|" + myString + "|"); 
     for (int j = 0; j < 3; j++) { 
       String valString = myFormat.format(
        scaling*m[i][j], new StringBuffer(), fp).toString(); 
     // With a max field width of w, we pack spaces before val. 
       valString = getSpaces(4 - fp.getEndIndex()) + valString; 
       outext.append(valString); 
     } 

     // Print each row, elements separated by spaces 
      for (int j = 3; j < n2; j++) 
       { 
      // Scaling is in thousandths; but note if +ve only. 
      w = 4;  // All cntr and corr are positive. 
      if (j/3 == (double)j/3.0) { // Here, will handle proj. 
      outext.append("|"); 
      w = 5;     // Allow for -ve vals. 
      } 
        String valString = myFormat.format(
         scaling*m[i][j], new StringBuffer(), fp).toString(); 
      // With max field width of w, we pack spaces before val. 
        valString = getSpaces(w - fp.getEndIndex()) + valString; 
        outext.append(valString); 
       } 
     outext.append("|"); 
      // Start a new line at the end of a row 
     outext.append("\n"); 
     } 
} 
+0

これは無料サービスのコードではありません。コード固有の問題を解決するためのコミュニティです。あなたのために書かれたことを試みる前に、あなた自身の質問を試みてください。どこから始めるべきかわからない場合、[PHP.net](http://php.net)は素晴らしいリソースです。 – Darren

+0

ありがとうございました – xaza

答えて

1

はい、あなたがPHPを使用してこの機能を実行できます。 はここのコードです。これを行う組み込み関数はありませんので、自分でコードを作成する必要があります

関数を分割していくつかのPHPコードを使ってみることをお勧めします。役職。

+0

ありがとうございました – xaza