This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Author: Keyvan Minoukadeh | |
This script demonstrates how you can set callback functions | |
to receive the HTTP response as it comes through. | |
The advantage of this is that you don't have to wait for the whole response | |
to be returned before you start work on it, you can monitor for certain headers, | |
start outputting while you're receiving, etc.. | |
I wasn't aware these cURL options were available in PHP, | |
but noticed them being used by Alan Knowles: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// is cURL installed yet? | |
if (!function_exists('curl_init')){ | |
die('Sorry cURL is not installed!'); | |
} | |
// OK cool - then let's create a new cURL resource handle | |
$ch = curl_init(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$con=mysqli_connect("example.com","peter","abc123","my_db"); | |
// Check connection | |
if (mysqli_connect_errno()) | |
{ | |
echo "Failed to connect to MySQL: " . mysqli_connect_error(); | |
} | |
$result = mysqli_query($con,"SELECT * FROM Persons"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setFullScreen(elm) { | |
w = $(document).width(); | |
h = $(document).height(); | |
$(elm).css({ | |
"height" : h, | |
"width" : w | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setCenter(elm) { | |
w = $(window).width(); | |
lr = ( w - $(elm).width() ) / 2; | |
h = $(window).height(); | |
tb = ( h - $(elm).height() ) / 2; | |
$(elm).css({ | |
"margin-left" : lr, | |
"margin-right" : lr, | |
"margin-top" : tb, | |
"margin-bottom" : tb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('textarea[maxlength]').live('keyup blur', function() { | |
// Store the maxlength and value of the field. | |
var maxlength = $(this).attr('maxlength'); | |
var val = $(this).val(); | |
// Trim the field if it has content over the maxlength. | |
if (val.length > maxlength) { | |
$(this).val(val.slice(0, maxlength)); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function file_get_contents_curl($url) { | |
$data = '' ; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_HEADER, 0); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser. | |
curl_setopt($ch, CURLOPT_URL, $url); | |
$data = curl_exec($ch); | |
curl_close($ch); | |
return $data; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (!filter_var($address, FILTER_VALIDATE_EMAIL)) { | |
// invalid e-mail address | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
date_default_timezone_set('Asia/Ho_Chi_Minh'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function khongdau($str) { | |
$str = preg_replace("/(à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ)/", "a", $str); | |
$str = preg_replace("/(è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ)/", "e", $str); | |
$str = preg_replace("/(ì|í|ị|ỉ|ĩ)/", "i", $str); | |
$str = preg_replace("/(ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ)/", "o", $str); | |
$str = preg_replace("/(ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ)/", "u", $str); | |
$str = preg_replace("/(ỳ|ý|ỵ|ỷ|ỹ)/", "y", $str); | |
$str = preg_replace("/(đ)/", "d", $str); | |
$str = preg_replace("/(À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ)/", "A", $str); | |
$str = preg_replace("/(È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ)/", "E", $str); |