-1
我正在處理一個字符串的哈希操作並獲取一個hasnumber,然後取消一個數字來取回一個字符串。下面是我對它的Java版本:在編譯php程序時出現語法錯誤(文件的意外結束,期待','或';')
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 Parse error: syntax error, unexpected end of file, expecting ',' or ';' in /home/mNw4IK/prog.php on line 16
任何想法什麼是錯的或任何其他更好的方式來寫這個?
@ user1234超出了這個問題的範圍。 –