Esempio n. 1
0
 function filename()
 {
     foreach ($_FILES as $file) {
         $name = explode('.', $file['name']);
         $ext = end($name);
         $name = $name[0];
     }
     $pinyin = new Pinyin();
     $pattern = '/[^\\x{4e00}-\\x{9fa5}\\d\\w]+/u';
     $name = preg_replace($pattern, '', $name);
     $name = substr($pinyin->output($name, true), 0, 80);
     if (file_exists(__ROOTDIR__ . '/upload/' . date('Y-m') . '/' . date('d') . '/' . $name . '.' . $ext)) {
         $rand = '-' . substr(cp_uniqid(), -5);
     }
     return $name . $rand;
 }
Esempio n. 2
0
 public function get_urltitle($name = '', $urlname = null, $aid = null)
 {
     if (empty($name)) {
         return false;
         exit;
     }
     if (empty($urlname)) {
         $pinyin = new Pinyin();
         $name = preg_replace('/\\s+/', '-', $name);
         $pattern = '/[^\\x{4e00}-\\x{9fa5}\\d\\w\\-]+/u';
         $name = preg_replace($pattern, '', $name);
         $urlname = substr($pinyin->output($name, true), 0, 30);
         if (substr($urlname, 0, 1) == '-') {
             $urlname = substr($urlname, 1);
         }
         if (substr($urlname, -1) == '-') {
             $urlname = substr($urlname, 0, -1);
         }
     }
     $where = '';
     if (!empty($aid)) {
         $where = 'AND aid<>' . $aid;
     }
     $info = $this->model->table('content')->where("urltitle='" . $urlname . "'" . $where)->count();
     if (empty($info)) {
         return $urlname;
     } else {
         return $urlname . substr(cp_uniqid(), 8);
     }
 }
Esempio n. 3
0
/**
 * 中文字符转拼音
 *
 * @param string $str
 * @param string $utf8
 */
function string_to_pinyin($str, $utf8 = true)
{
    static $obj = null;
    if ($obj === null) {
        $obj = new Pinyin();
    }
    return $obj->output($str, $utf8);
}
Esempio n. 4
0
/**
 * 汉字转拼音
 * @param string $srt
 * @return Ambigous <string, boolean, unknown>
 */
function get_pinyin($srt = '')
{
    $py = new Pinyin();
    return $py->output($srt);
    // 输出
}