Skip to content

Instantly share code, notes, and snippets.

View liuxd's full-sized avatar
🗿
Hi, there.

Allen Liu liuxd

🗿
Hi, there.
  • Tax Traders
  • Auckland, New Zealand
View GitHub Profile
@liuxd
liuxd / iniEditor.php
Created September 7, 2017 01:08
iniEditor.php
<?php
/**
* 将数组写入ini文件。
* @param array $array 待写入的数组。
* @param string $file ini文件路径。
* @return bool
*/
function iniEditor($array, $file)
{
$res = [];
@liuxd
liuxd / image_zoom.php
Created September 7, 2017 01:08
image_zoom.php
<?php
/**
* 图片的等比缩放
*/
// 因为PHP只能对资源进行操作,所以要对需要进行缩放的图片进行拷贝,创建为新的资源。
$src = imagecreatefromjpeg('origin.jpg');
// 取得源图片的宽度和高度
$size_src = getimagesize('origin.jpg');
$w = $size_src['0'];
$h = $size_src['1'];
@liuxd
liuxd / image_watermark.php
Created September 7, 2017 01:08
image_watermark.php
<?php
/**
* 给图片打水印。
*/
// 原图
$dst = "bg.jpg";
$dst_im = imagecreatefromjpeg($dst);
$dst_info = getimagesize($dst);
// 水印图
$src = "shuiyin.jpg";
@liuxd
liuxd / getMemcachedStat.php
Created September 7, 2017 01:07
getMemcachedStat.php
<?php
/**
* 获得memcached服务的状态信息。不需要额外的pecl扩展。
* @param string $host
* @param int $port
* @return array
*/
function getMemcachedStat($host, $port)
{
$s = fsockopen($host, $port, 1);
@liuxd
liuxd / factorial.php
Created September 7, 2017 01:07
factorial.php
<?php
/**
* 计算阶乘。注:解决了大数显示问题。
*
* @param int $n
* @return string
*/
function factorial($n)
{
if ($n < 0) {
@liuxd
liuxd / download.php
Created September 7, 2017 01:07
download.php
<?php
function download($sContent, $sFileName)
{
header("Content-type: application/octet-stream");
header("Accept-Length: " . mb_strlen($sContent));
header("Content-Disposition: attachment; filename=" . $sFileName);
echo $sContent;
}
# end of this file.
@liuxd
liuxd / colorful_echo_for_cli.php
Created September 7, 2017 01:06
colorful_echo_for_cli.php
<?php
/**
* Colorful echo.
* @param string $string The string you want to show.
* @param string $style Color theme.It can be:notic, info, error, system.
*/
function cecho($string, $style = 'info')
{
if (PHP_SAPI !== 'cli') {
echo $string, "\n";
@liuxd
liuxd / XssFilter.php
Created September 7, 2017 01:06
XssFilter.php
<?php
/**
* Prevent XSS.
* Allowing you to add permmited tags or attributes.
*
* @author liuxd
*/
class XssFilter
{
/**
@liuxd
liuxd / ImageStringConverter.php
Created September 7, 2017 01:06
ImageStringConverter.php
<?php
/**
* 图片与字符串互相转换。
*/
class ImgPipString
{
/**
* 图片转字符串
* @param string $file 图片文件路径。
* @return string
@liuxd
liuxd / get-checked-radio-value.js
Last active September 7, 2017 01:19
[get-checked-radio-value.js] #jQuery
$("input[name=input_name]:checked").val();