Skip to content

Instantly share code, notes, and snippets.

View phamquocbuu's full-sized avatar
💻

Buu Pham phamquocbuu

💻
View GitHub Profile
@phamquocbuu
phamquocbuu / set_utf_8.php
Created October 5, 2013 01:44
PHP Set charset UTF-8
header('Content-Type: text/html; charset=utf-8');
@phamquocbuu
phamquocbuu / newline_to_space.php
Created October 5, 2013 01:45
PHP Replace newline char by space
$content = nl2br($content);
$remove = array("\n", "\r\n", "\r", "<p>", "</p>", "<h1>", "</h1>", "<br>", "<br />", "<br/>");
$content = str_replace($remove, ' ', $content);
@phamquocbuu
phamquocbuu / add_text_to_image.php
Created October 5, 2013 01:46
PHP Add text to image
//Set the Content Type
header('Content-type: image/jpeg');
// Create Image From Existing File
$jpg_image = imagecreatefromjpeg('1.jpg');
// Allocate A Color For The Text
$white = imagecolorallocate($jpg_image, 255, 255, 255);
// Set Path to Font File
@phamquocbuu
phamquocbuu / ajax_check.php
Created October 5, 2013 02:36
PHP Check if the request is AJAX From http://davidwalsh.name/detect-ajax
/* decide what the content should be up here .... */
$content = get_content(); //generic function;
/* AJAX check */
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
/* special ajax here */
die($content);
}
/* not ajax, do more.... */
@phamquocbuu
phamquocbuu / set_width_include_padding_margin.css
Created October 15, 2013 02:52
CSS Set width included the padding and margin
-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
-moz-box-sizing: border-box; /* Firefox, other Gecko */
box-sizing: border-box; /* Opera/IE 8+ */
@phamquocbuu
phamquocbuu / header_chartset_utf-8.php
Created October 17, 2013 04:09
PHP Set chartset to UTF-8 by header
header('Content-Type: text/html; charset=utf-8');
@phamquocbuu
phamquocbuu / random_string.php
Created October 18, 2013 03:07
PHP Create random string
function getRandomString($length = 5, $encryption_level = 5){
$str = '';
for($i=0;$i<$encryption_level;$i++){
$str = base64_encode(md5(microtime(true)).$str);
}
return substr($str, 0, $length);
}
@phamquocbuu
phamquocbuu / set_charset_utf_8_mysql.php
Created October 19, 2013 02:03
PHP Set charset UTF-8 for MySQL
mysqli_query($con, "SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'");
@phamquocbuu
phamquocbuu / echo.php
Last active December 25, 2015 22:59
Test Gist
<?php
echo "con khi gio";
@phamquocbuu
phamquocbuu / unserialize.php.js
Created November 5, 2013 02:23
JS Unserialize Function. Unserialize PHP data to JS data.
function unserialize (data) {
var that = this,
utf8Overhead = function (chr) {
// http://phpjs.org/functions/unserialize:571#comment_95906
var code = chr.charCodeAt(0);
if (code < 0x0080) {
return 0;
}
if (code < 0x0800) {
return 1;