PHP十进制数字转换为26进制字母函数

很久以前为导出EXCEL写过一个字母累加的函数,今天追加一个数字转为字母的。也就是十进制转26进制。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
for ($i = 1; $i < 200; $i++) {
echo $i . ' : ' . num2Letter($i) . '<br />';
}
function num2Letter($num) {
$num = intval($num);
if ($num <= 0)
return false;
$letterArr = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
$letter = '';
do {
$key = ($num - 1) % 26;
$letter = $letterArr[$key] . $letter;
$num = floor(($num - $key) / 26);
} while ($num > 0);
return $letter;
}

解决SFTP时,NetBeans恼人的RSA提示

使用NetBeans SFTP建立远程项目的时候,总是会有RSA提示,百度搜索不得其果,转向GOOGLE,在NetBeans的官方论坛找到了解决方法,留作备忘。

原文:

 


1. Go in your project's properties and select "Run Configurations".
2. Hit "Manage" next to the Remote Connections ddl
3. Select the connection you are using and hit Browse next to the Known Hosts File box. Select a file (you may need to create an empty file beforehand)
4. Now select "Test Connection" - It should prompt you for the RSA Fingerprint confirmation - Select "Yes".
5. Select "Test Connection" again - At this point it should only report the result of the connection test - no more RSA messages.

Sincerely,
Stephan


 

译文 By Yuanjun.Liu:

 


1. 进入你的项目的<属性>,然后选择<运行配置>。
2. 点击<管理>,进入 管理远程连接
3. 选择你使用的连接,点击<浏览>,选择一个文件。(你需要事先创建一个空白文件)
4. 选择<测试连接> - 这时应该弹出
RSA Fingerprint confirmation提示,选择<是>。
5. 再次选择
<测试连接> - 这时应该只会提示连接结果了,不在有RSA信息。

真诚的,
Stephan


 

原文链接: http://forums.netbeans.org/topic27555.html

PHP文件缓存函数

发一个自己写的PHP文件缓存函数


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
+----------------------------------------------------------
* PHP文件缓存函数
* @author LiuYuanjun <http://www.liuyuanjun.com>
+----------------------------------------------------------
* @param string $key 缓存KEY 设为null则清空所有缓存
* @param mixed $data 缓存内容 设为null则删除KEY为$key的缓存
* @param int $time 缓存时间 秒数,如果大于当前时间戳则按照时间戳来处理,为0则永不过期
+----------------------------------------------------------
* @return mixed
+----------------------------------------------------------
*/
function file_cache($key, $data='', $time=0) {
$cacheDir = ROOTPATH . 'Cache' . DS; //这里设置缓存目录
$timestamp = time();
if ($key === null) { //clear all
$dirFiles = scandir($cacheDir);
foreach ($dirFiles as $dirFile) {
if ($dirFile != '.' && $dirFile != '..')
@unlink($cacheDir . $dirFile);
}
}
$cachePath = $cacheDir . '~' . $key . '.php';
if ($data === '') { //get cache
if (!is_file($cachePath))
return false;
$cacheData = @require $cachePath;
if ($cacheData[0] > 0 && $cacheData[0] < $timestamp) {
@unlink($cachePath);
return false;
} else {
return @unserialize($cacheData[1]);
}
}
if ($data === null)
@unlink($cachePath); //delete cache
$time = intval($time);
$deadline = $time == 0 ? 0 : ($time>$timestamp?$time:($timestamp+$time));
$storeData = '<?php return array(' . $deadline . ',\'' . serialize($data) . '\'); ?>';
@file_put_contents($cachePath, $storeData);
}

重写了NHK新闻下载器

NHK页面变了好久,下载器一直处于无法正常抓取的状态。

稳定的访问量降没了才重写,我真是懒到贱啊。。哈哈

地址:http://dodojp.com/tools/nhk/

基于JQUERY写的打豆豆小游戏

几个月前写的。

开始游戏