2015-11-06 53 views
0

我试图使用从这里PHP短网址: https://github.com/delight-im/ShortURL找不到为什么功能是不确定的,PHP的错误

我只是拷入这个代码,并与多家试过,但我有一个PHP错误“调用未定义的函数encode()”。 我找不到问题。

你能帮我

这里是我的代码:

<!doctype html> 
<html> 
<head> 
<meta charset="utf-8"> 
<title>Document sans titre</title> 
</head> 

<body> 

<?php 

/** 
* ShortURL: Bijective conversion between natural numbers (IDs) and short strings 
* 
* ShortURL::encode() takes an ID and turns it into a short string 
* ShortURL::decode() takes a short string and turns it into an ID 
* 
* Features: 
* + large alphabet (51 chars) and thus very short resulting strings 
* + proof against offensive words (removed 'a', 'e', 'i', 'o' and 'u') 
* + unambiguous (removed 'I', 'l', '1', 'O' and '0') 
* 
* Example output: 
* 123456789 <=> pgK8p 
* 
* Source: https://github.com/delight-im/ShortURL (Apache License 2.0) 
*/ 
class ShortURL { 
    const ALPHABET = '23456789bcdfghjkmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ-_'; 
    const BASE = 51; // strlen(self::ALPHABET) 

    public static function encode($num) { 
     $str = ''; 
     while ($num > 0) { 
      $str = substr(self::ALPHABET, ($num % self::BASE), 1) . $str; 
      $num = floor($num/self::BASE); 
     } 
     return $str; 
    } 

    public static function decode($str) { 
     $num = 0; 
     $len = strlen($str); 
     for ($i = 0; $i < $len; $i++) { 
      $num = $num * self::BASE + strpos(self::ALPHABET, $str[$i]); 
     } 
     return $num; 
    } 

} 
ShortURL.encode(5356); 


?> 
</body> 
</html> 
+4

你看到在该类顶部的意见,你怎么看你在做什么? – ODelibalta

回答

4

使用它这样的:

ShortURL::encode(5356); 
相关问题