PHP Simple Pagination
<?php
/*
$perpage = $_GET['pp'];
$total = $_GET['total'];
$currentpage = $_GET['c'];
$p = simple_pagination($perpage, $total, $currentpage);
echo $_POST['limit'];
echo "?>PHP User Info
<?php
/*
$userinfo = UserInfo(false);
return data is string.
$userinfo = UserInfo(true);
return data is array('ip', 'host', 'httpvia', 'date', 'browser', 'requesturi');
*/
function UserInfo($array=false){
if (getenv('HTTP_CLIENT_IP')) {
$ips[] = getenv('HTTP_CLIENT_IP');
}
if (getenv('HTTP_X_FORWARDED_FOR')) {
$ips[] = getenv('HTTP_X_FORWARDED_FOR');
}
if (getenv('HTTP_X_FORWARDED')) {
$ips[] = getenv('HTTP_X_FORWARDED');
}
if (getenv('HTTP_FORWARDED_FOR')) {
$ips[] = getenv('HTTP_FORWARDED_FOR');
}
if (getenv(HTTP_?>Convert English Number to Kurdish (1 = > یەک)
<?php
function KuNumbersWriting($number){
$kuindex = array( 0=> 'سفر', 1 => 'یەک', 'دوو', 'سێ', 'چوار', 'پێنج', 'شەش', 'حەوت', 'هەشت', 'نۆ',
11 => 'یازدە', 12 => 'دوازدە', 13 => 'سێزدە', 14 => 'چواردە', 15 => 'پازدە', 16 => 'شازدە', 17 => 'حەڤدە', 18 => 'هەژدە', 19 => 'نۆزدە',
10 => 'دە', 20 => 'بیست', 30 => 'سی', 40 => 'چل', 50 => 'پەنجا', 60 => 'شەست', 70 => 'حەفتا', 80 => 'هەشتا', 90 => 'نەوەد',
100 => 'سەد',
1000 => 'هەزار');?>PHP Input Filter
Before inserting data to mysql
$postdata = InputFilter($postdata, 'encode');
Getting data from MySQL
$row= InputFilter($row, 'decode');
The data converts to Unicode entities, you don't need to decode it, except for file names or...
<?php
/* ***********************************************
* Function reset_magic_quotes($data)
* ***********************************************/
function reset_magic_quotes($data){
if(get_magic_quotes_gpc() || get_magic_quotes_runtime()) {
if(is_array($data)){
$data = array_map("reset_magic_quotes", $data);
?>PHP Function - Convert (M byte, K byte,..) to (مێگا بایت..)
<?php
/* $bytes = filesize($file); */
function formatBytes($bytes, $precision = 2) {
$units = array('B', 'KB', 'MB', 'GB', 'TB');
$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);
$bytes /= pow(1024, $pow);
$ensize = array('KB', 'MB', 'GB', 'TB', 'B');
$kusize = array('کیلۆ بایت', 'مێگا بایت', 'گێگا بایت', 'تێڕا بایت', 'بایت');
return round($bytes, $precision) . ' ' .?>PHP Function - Mime types
<?php
function GetMime($file){
$file = basename($file);
$ext = substr(strrchr($file, "."), 1);
$mimes = array(
"*" => "application/octet-stream",
"" => "application/octet-stream",
"0" => "application/octet-stream",
false => "application/octet-stream",
null => "application/octet-stream",
"ac" => "text/plain",
"acx" => "application/internet-property-stream",
"ai" => "application/postscript",
"aif" => "audio/x-aiff",
"aifc" => "audio/x-aiff",
"aiff" => "audio/x-aiff",
"asc" => "text/plain",
"asf" => "video/x-ms-asf",
"asr" => "video/x-m?>Convert English Number to Kurdish (1 => ١, 2 => ٢, ..)
<?php
function KuNumber($number){
$en =array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
$ku =array('٠', '١', '٢', '٣', '٤', '٥', '٦', '٧','٨', '٩');
return str_replace($en, $ku, $number);
}
?>PHP Find and Replace in File
<?php
echo <<<A
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Language" content="en-us" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Dir</title>
</head>
<body>
A;
$dir = !empty($_POST['dir'])??>Variable Scope in PHP
Many Times Globality of variables will be the small issue, after long time I decided to use super globals. Super globals exists any where: $_SERVER, $_GET, $_POST .....
PHP Manual