编译 PHP 程序时出现语法错误(文件意外结尾,预期','或";")



我正在努力录制字符串并获取hasnumber,然后毫不及格地将字符串返回。以下是我的Java版本:

public class Hashcode {
  private static final String ALPHABET = "acegikmnoprstuvy";
  public static long hash(String s) {
    long h = 7;
    for (int i = 0; i < s.length(); i++) {
      h = (h * 37 + ALPHABET.indexOf(s.charAt(i)));
    }
    return h;
  }
  public static String unhash(long n) {
    String result = "";
    while (n > 7) {
      result = ALPHABET.charAt((int) (n % 37)) + result;
      n = n / 37;
    }
    if (n != 7) {
      System.err.println("Error, hash parity incorrect.");
      System.exit(1);
    }
    return result;
  }
  public static void main(String[] args) {
    System.out.println(hash("reports"));
    System.out.println(unhash(690336378753L));
    System.out.println(unhash(932246728227799L));
    System.out.println(hash("mymitsapp"));
  }
}

现在,我试图在PHP中进行相同的练习,如下所示,但它给了我一个错误:

function unhash($h) {  
    $letters = "acegikmnoprstuvy";
    $s='';
    while ($h>7){
        //hold
        $pos = fmod($h, 37);
        $s = $letters[$pos].$s;
        $h = ($h-$pos) / 37 ;
    }
    return $s;
}

以下是一个错误,这是IDEONE链接。

php解析错误:语法错误,文件的意外结束,期望',''或;''在/home/mnw4ik/prog.php中,第16行

有什么想法是什么问题或其他更好的写作方法?

错误是在说它期望,;

您有:

echo $something 

,但应该是:

echo $something;

希望这会有所帮助!

最新更新