Example #1
0
 function outlink($link)
 {
     if (!preg_match('/^http(s)?:\\/\\/(.*?)/i', $link)) {
         return '';
     }
     $short_link = shorturl($link);
     $linkinfo = array('shorturl' => $short_link[0], 'realadd' => urlencode($link));
     $aid = $this->attach($linkinfo, 'link');
     return $aid;
 }
Example #2
0
    //要修改这里的key再测试哦
    $apiUrl = 'http://api.t.sina.com.cn/short_url/shorten.json?source=' . $apiKey . '&url_long=' . $long_url;
    $response = file_get_contents($apiUrl);
    $json = json_decode($response);
    return $json[0]->url_short;
}
function expandurl($short_url)
{
    $apiKey = '3738750665';
    //要修改这里的key再测试哦
    $apiUrl = 'http://api.t.sina.com.cn/short_url/expand.json?source=' . $apiKey . '&url_short=' . $short_url;
    $response = file_get_contents($apiUrl);
    $json = json_decode($response);
    return $json[0]->url_long;
}
$str1 = shorturl($urlget);
if ($str1 == '') {
    echo '<SCRIPT language=JavaScript>alert("请填写正确的网址!")</SCRIPT>';
    echo '<meta http-equiv="refresh" content="0.1;url=index.html">';
    return 0;
}
function getRandom($param)
{
    $str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    $key = "";
    for ($i = 0; $i < $param; $i++) {
        $key .= $str[mt_rand(0, 32)];
        //生成php随机数
    }
    return $key;
}
Example #3
0
     if ($trim == '') {
         unset($page_path_part[$i]);
     } else {
         $page_path_part[$i] = $trim;
     }
 }
 reset($page_path_part);
 $page_path = implode('/', $page_path_part);
 if ($page_title == '') {
     $error_msg = '页面标题不能为空';
 } else {
     if ($page_path == '') {
         $error_msg = '固定链接不能为空';
     } else {
         if ($page_file == '') {
             $file_names = shorturl($page_title);
             foreach ($file_names as $file_name) {
                 $file_path = '../mc-files/pages/data/' . $file_name . '.dat';
                 if (!is_file($file_path)) {
                     $page_file = $file_name;
                     break;
                 }
             }
         } else {
             $file_path = '../mc-files/pages/data/' . $page_file . '.dat';
             $data = unserialize(file_get_contents($file_path));
             $page_old_path = $data['path'];
             $page_old_state = $data['state'];
             if ($page_old_state != $page_state || $page_old_path != $page_path) {
                 $index_file = '../mc-files/pages/index/' . $page_old_state . '.php';
                 require $index_file;
Example #4
0
 for ($i = 0; $i < $post_tags_count; $i++) {
     $trim = trim($post_tags[$i]);
     if ($trim == '') {
         unset($post_tags[$i]);
     } else {
         $post_tags[$i] = $trim;
     }
 }
 reset($post_tags);
 if ($post_title == '') {
     //标题为空则自动命名
     $post_title = '未命名';
 } else {
     if ($post_id == '') {
         //新建文章
         $file_names = shorturl($post_title);
         foreach ($file_names as $file_name) {
             $file_path = '../mc-files/posts/data/' . $file_name . '.dat';
             if (!is_file($file_path)) {
                 $post_id = $file_name;
                 break;
             }
         }
     } else {
         //编辑文章
         $file_path = '../mc-files/posts/data/' . $post_id . '.dat';
         $data = unserialize(file_get_contents($file_path));
         $post_old_state = $data['state'];
         if ($post_old_state != $post_state) {
             $index_file = '../mc-files/posts/index/' . $post_old_state . '.php';
             require $index_file;
Example #5
0
    $subHexLen = $hexLen / 8;
    $output = array();
    for ($i = 0; $i < $subHexLen; $i++) {
        $subHex = substr($hex, $i * 8, 8);
        $int = 0x3fffffff & 1 * ('0x' . $subHex);
        $out = '';
        for ($j = 0; $j < 6; $j++) {
            $val = 0x1f & $int;
            $out .= $base32[$val];
            $int = $int >> 5;
        }
        $output[] = $out;
    }
    return $output;
}
$a = shorturl("http://www.jb51.net");
print_r($a);
//62 位生成方法
function base62($x)
{
    $show = '';
    while ($x > 0) {
        $s = $x % 62;
        if ($s > 35) {
            $s = chr($s + 61);
        } elseif ($s > 9 && $s <= 35) {
            $s = chr($s + 55);
        }
        $show .= $s;
        $x = floor($x / 62);
    }
Example #6
0
<?php

function code62($x)
{
    $show = '';
    while ($x > 0) {
        $s = $x % 62;
        if ($s > 35) {
            $s = chr($s + 61);
        } elseif ($s > 9 && $s <= 35) {
            $s = chr($s + 55);
        }
        $show .= $s;
        $x = floor($x / 62);
    }
    return $show;
}
function shorturl($url)
{
    $url = crc32($url);
    $result = sprintf("%u", $url);
    return code62($result);
}
echo shorturl("http://pai.game.weibo.com/love/") . "<br>";
echo shorturl("http://www.oschina.net/code/snippet_878945_22499") . "<br>";
/**
 * print meta shortlink
 *
 */
function shortlink()
{
    if (function_exists('\\is_singular') && \is_singular()) {
        $url = shorturl();
        if (!empty($url)) {
            printf('<link rel="shortlink" href="%s" />%s', shorturl(), "\n");
        }
    }
}