php中的格式文本[关闭]

I have this code in java and i want to convert it into php. With this function i want to format some data and write them in a txt file.

Is there any classes as the text class in java to handle it? here is the code :

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("
");
      }
}

Yes, you can do this function using PHP. There is no built-in function that does this, so you must code it yourself

I suggest you start breaking the function down into pieces and try using some PHP code, then if you get stuck search for that specific question before you post.