Skip to content

Instantly share code, notes, and snippets.

View vhdm's full-sized avatar
🎯
Focusing

Vahid vhdm

🎯
Focusing
View GitHub Profile
@vhdm
vhdm / convert_number_to_persion.php
Created September 13, 2015 17:33
Convert number to persion in php
function persian_digit($text){
$text = str_replace('0' , '٠' , $text);
$text = str_replace('1' , '١' , $text);
$text = str_replace('2' , '٢' , $text);
$text = str_replace('3' , '٣' , $text);
$text = str_replace('4' , '۴' , $text);
$text = str_replace('5' , '۵' , $text);
$text = str_replace('6' , '۶' , $text);
$text = str_replace('7' , '٧' , $text);
$text = str_replace('8' , '٨' , $text);
@vhdm
vhdm / convert_number_to_persion.js
Created September 9, 2015 21:55
Convert number to persion in javascript
$(document).ready(function(){
convert_number_to_persion();
});
function convert_number_to_persion() {
persian = {0: '۰', 1: '۱', 2: '۲', 3: '۳', 4: '۴', 5: '۵', 6: '۶', 7: '۷', 8: '۸', 9: '۹'};
function traverse(el) {
if (el.nodeType == 3) {
var list = el.data.match(/[0-9]/g);
if (list != null && list.length != 0) {
@vhdm
vhdm / states_and_cities.txt
Created September 8, 2015 19:40
Iranian states and cities
CREATE TABLE `cities` (
`id` int(11) NOT NULL auto_increment,
`cid` int(11) default NULL,
`cityname` varchar(200) character set utf8 collate utf8_persian_ci default NULL,
PRIMARY KEY (`id`));
CREATE TABLE `state` (
`id` int(11) NOT NULL auto_increment,
`statename` varchar(200) character set utf8 collate utf8_persian_ci default NULL,
PRIMARY KEY (`id`));
@vhdm
vhdm / simplexlsx.class.php
Created September 6, 2015 22:45
Read excel files in php (*.xlsx)
<?php
/*
SimpleXLSX php class v0.6.8
MS Excel 2007 workbooks reader
Example 1:
$xlsx = new SimpleXLSX('book.xlsx');
print_r( $xlsx->rows() );
Example 2:
@vhdm
vhdm / image_to_text.php
Created September 6, 2015 22:39
Image to text (ASCII Image)
<!doctype html>
<html>
<head>
<title>ASCII Image</title>
</head>
<body>
<?php
function ascii_image($image) {
$result = '';
if(file_exists($_GET['image'])) {
@vhdm
vhdm / randomColor.php
Created September 6, 2015 22:23
Generate random color
<?php
function randomColor() {
$str = '#';
for($i = 0 ; $i < 6 ; $i++) {
$randNum = rand(0 , 15);
switch ($randNum) {
case 10: $randNum = 'A'; break;
case 11: $randNum = 'B'; break;
case 12: $randNum = 'C'; break;
case 13: $randNum = 'D'; break;
@vhdm
vhdm / word_of_day.php
Created September 6, 2015 22:16
Word of the day
<?php
function wordofday(){
$filename = "words.txt";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
$array = explode("\n",$contents);
$date = date("z");
if($date > count($array)){
return $array[0];
@vhdm
vhdm / birthday.php
Created September 6, 2015 22:10
Age calculator
<?php
function birthday($birthday){
$age = strtotime($birthday);
if($age === FALSE){
return FALSE;
}
list($y1,$m1,$d1) = explode("-",date("Y-m-d",$age));
$now = strtotime("now");
list($y2,$m2,$d2) = explode("-",date("Y-m-d",$now));
$age = $y2 - $y1;
@vhdm
vhdm / countrylist.php
Last active September 6, 2015 22:01
Get country list
<?php
function countrylist($action = 'dropdown', $selectedid = null) {
$country_list = array(
"Afghanistan",
"Albania",
"Algeria",
"Andorra",
"Angola",
"Antigua and Barbuda",
"Argentina",
@vhdm
vhdm / time_zone.php
Created September 6, 2015 21:58
Set time zone
<?php
// This is for Central Standard Time
ini_set('date.timezone','America/Chicago');
echo '<p>'.date("g:i A").'</p>';
ini_set('date.timezone','Asia/Tehran');
echo '<p>'.date("g:i A").'</p>';
?>