Skip to content

Instantly share code, notes, and snippets.

View easychen's full-sized avatar
❄️
休息,休息一会儿

Easy easychen

❄️
休息,休息一会儿
View GitHub Profile
@easychen
easychen / gist:9658330
Created March 20, 2014 06:25
相对时间函数
<?php
function rtime($time = false, $limit = 86400, $format = 'Y-m-d H:i')
{
if(empty($time)||(!is_string($time)&& !is_numeric($time)))
$time = time();
elseif (is_string($time))
$time = strtotime($time);
$now = time();
$relative = '';
<?php
function is_email( $email )
{
return filter_var($email, FILTER_VALIDATE_EMAIL);
}
@easychen
easychen / get_title_via_url.php
Last active December 25, 2015 15:49
做了下title转码、对于文件链接只取前1k(服务器支持断点下载的情况下
<?php
function get_title_via_url( $url )
{
// 抓取前1024个字节
$context=array('http' => array ('header'=> 'Range: bytes=0-1024' ));
$xcontext = stream_context_create($context);
$content = strtolower( file_get_contents( $url , FALSE,$xcontext ) );
$reg = '/<title>(.+?)<\/title>/is';
@easychen
easychen / route.php
Created June 20, 2017 08:34
让PHP build-in web server支持跨域: php -S locahost:4000 route.php
<?php
if (file_exists($_SERVER["SCRIPT_FILENAME"]))
{
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: origin,x-requested-with,content-type');
header('Access-Control-Allow-Methods: PUT,GET,POST,DELETE,OPTIONS');
readfile($_SERVER["SCRIPT_FILENAME"]);
@easychen
easychen / json.php
Created June 25, 2017 02:35
微贝增强脚本:Json导出
<?php
foreach( glob( '*.html' ) as $k => $htmlfile )
{
echo "File $htmlfile ...";
$reg = '/this\.feeds\s+=\s+(.+?)\}\s+,\s+1000/is';
$content = file_get_contents( $htmlfile );
@easychen
easychen / img.php
Last active June 25, 2017 02:57
微贝增强脚本:图片备份
<?php
foreach( glob( '*.html' ) as $k => $htmlfile )
{
echo "File: $htmlfile \r\n";
$reg = '/this\.feeds\s+=\s+(.+?)\}\s+,\s+1000/is';
@easychen
easychen / get_302_location.php
Last active July 16, 2017 06:29
获取url对应的302跳转地址
<?php
function get_302_location( $url )
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
git clone https://github.com/easychen/fangPHP && cd fangPHP
# install docker-compose
sudo curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose && sudo chmod +x /usr/local/bin/docker-compose
docker-compose up
@easychen
easychen / list.array
Created January 31, 2018 04:08
php函数使用频次列表(GitHub统计)
Array
(
[define] => 1B
[file] => 1B
[list] => 1B
[copy] => 1B
[end] => 1B
[array] => 827M
[time] => 810M
[max] => 751M
<?php
function indexController
{
// model
$data = $db->getUserInfo();
// view
$html = $render->toHtml( $data , 'index.tpl.html' );