杜郎俊赏 - dujun.io

984封面
看到博友 gd1214b 的文章《Web Feed 倡议书》,增加了 RSS 自动发现功能。 在 里增加: 效果如下:

2022-05-12

仿微信语音播放 svg

决定优化语音播放的动效,网上找了一圈没有满意的,最后自己用微信程序包中的 svg 来改。 svg 如下: 效果如下:

2022-04-08

rtrim 的坑

线上报 500 错误,定位到是 json 解析失败,特定内容存在乱码,而造成乱码的是原因是 rtrim 截取中文字符时末位可能乱码。 替代方法: function r_trim($content, $tail) { $len = mb_strlen($tail, 'utf-8'); return $tail == mb_substr($content, -$len, $len, 'utf-8') ? mb_substr($content, 0, -$len, 'utf-8') : $content; }

2019-02-01

mysql 列值转换和统计

将 user_sample uid 201608 201609 201610 201611 张三 iPhone mi mi Google 李四 mi mi Google Google 王五 Google mi iPhone iPhone 转换为 phone_result uid iPhone mi Google 张三 1 2 1 李四 0 2 2 王五 2 1 1 sql 如下: drop table if exists tmp; drop table if exists phone_result; create table tmp as select uid, `201608` as...

2017-09-13

62进制转换

//十进制转为 62 进制 function encode62($number) { $base = 62; $index = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $ret = ''; for ($t = floor(log10($number) / log10($base)); $t >= 0; $t--) { $a = floor($number / pow($base, $t)); $ret .= substr($index...

2017-08-31

建站之天气获取

写文章时自动抓取当前天气,找了几个 api 都不靠谱,直接采集中国天气网的数据。 例如采集富阳的天气地址: $url = 'http://www.weather.com.cn/weather/101210108.shtml'; $raw = file_get_contents($url); $raw = str_replace("\n", '', $raw); if (preg_match('', $raw, $match)) { //匹配到天气文字 }

2017-05-26

建站之视频处理

借助 ffmpeg 扩展处理视频。包括自动旋转、截图、转换格式等。 ubuntu 下安装扩展 sudo apt-get install ffmpeg 获取视频尺寸、旋转角度 /** * /usr/bin/ffprobe video.mp4 -show_streams -print_format json */ public static function info($video) { $raw = shell_exec(sprintf('%s %s -show_streams -print_format json', self::ffprobe(), $video))...

2017-05-18

建站之友好时间显示

public function format($time) { if (invalid_integer($time)) { return ''; } $now = time(); $today = strtotime(date('Y-m-d', $now)); $tmp = $now - $time; if (60 > $tmp) { return '刚刚'; } elseif (3600 > $tmp) { return floor($tmp / 60) . ' 分钟前'; }...

2017-05-18

建站之阿里云邮件推送

评论被回复时,如果评论者填了邮箱,则向其发送通知邮件。使用阿里云的邮件推送。每日免费额度 200 封。 /** * 发送阿里云邮件 */ class Util_Mail { private static $url, $accessId, $accessSecret, $account, $name; public static function send($title, $content, $receiver = null) { if (empty($title) || empty($content)) { return...

2017-05-18

建站之图片缩略图

难点在于,gif 图片直接截缩略图可能有巨大噪音,所以改为截取第一帧。 //生成缩略图 public static function createThumb($imagePath) { try { if (!($imagePath = File::exist($imagePath))) { return false; } if (is_mobile()) { //移动端生成更小的图 $path = $imagePath . '_s.jpg'...

2017-05-18

分页: 1 2 3