Skip to content

Instantly share code, notes, and snippets.

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

Easy easychen

❄️
休息,休息一会儿
View GitHub Profile
@easychen
easychen / weibopicbed.js
Created July 16, 2017 08:30
微博图床上传函数
// from https://github.com/suxiaogang/WeiboPicBed
// under its license
function uploadToWeibo( url , callback )
{
var xhr = new XMLHttpRequest();
xhr.onload = function() {
var reader = new FileReader();
reader.onloadend = function( e )
{
@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);
<?php
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');
@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 / 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 / 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"]);
<?php
function mypost( $url , $data )
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
<?php
function is_email( $email )
{
return filter_var($email, FILTER_VALIDATE_EMAIL);
}
@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 = '';
@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';