[ create a new paste ] login | about

balajimca

Name: Balaji
Email:
Site/Blog: http://stackoverflow.com/users/817365/balajimca
Location: India
Default language: PHP
Favorite languages: PHP,Javascript,HTML5,objective-C
About: Senior Software Engineer - Web

Saved pastes by balajimca:

PHP, pasted on Apr 26:
1
2
3
4
<?php
$str = "123456";
echo sha1($str);
?>
view (4 lines, 1 line of output)
PHP, pasted on Mar 25:
1
2
3
4
5
<?php
function test($s)
{

echo 'test';
...
view (12 lines, 1 line of output)
PHP, pasted on Jan 22:
1
2
3
4
5
<?php
$array = array(0 => 100, "color" => "red");
print_r(array_keys($array));

$array = array("blue", "red", "green", "blue", "blue");
...
view (11 lines, 16 lines of output)
PHP, pasted on Jan 12:
1
2
3
4
5
<?php
$string = 'April 15, 2003';
$pattern = '/(\w+) (\d+), (\d+)/i';
$replacement = '${1} 2,$3';
echo preg_replace($pattern, $replacement, $string);
...
view (6 lines, 1 line of output)
PHP, pasted on Dec 12:
1
2
3
4
5
<?php
$rate=12.00;
$percent = 5;
$newrate = ($rate - (($rate/100)*$percent));
print $newrate;
...
view (6 lines, 1 line of output)
PHP, pasted on Oct 27:
1
2
3
4
5
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
...
view (51 lines, 2 lines of output)
PHP, pasted on Oct 27:
1
2
3
4
5
<?php
if(isset($_POST[sub])) {
function find_user($filename, $email) {

$f = fopen($filename, "r");
...
view (27 lines, 5 lines of output)
PHP, pasted on Oct 8:
1
2
3
4
<?php
$date="1349697006";
echo date("m-d-Y",$date);
?>
view (4 lines, 1 line of output)
PHP, pasted on Oct 5:
1
2
3
4
5
<?php
$beginning = 'foo';
$end = array('bar');
$result = array_merge((array)$beginning, (array)$end);
print_r($result);
...
view (6 lines, 5 lines of output)
PHP, pasted on Oct 5:
1
2
3
4
5
<?php
$array = array(0 => 100, "color" => "red");
print_r(array_keys($array));

$array = array("blue", "red", "green", "blue", "blue");
...
view (11 lines, 16 lines of output)
PHP, pasted on Sep 25:
1
2
3
4
<?php
$string = '60, 1, 1, 188, pdgje5565';

$output_array = array_map('trim',explode(',',$string));
...
view (6 lines, 8 lines of output)
PHP, pasted on Sep 17:
1
2
3
4
5
<?php
$sites = array("Nettuts+"=>"ets", "Psdtuts+"=>"erre", "Mobiletuts+"=>"swa", "Mactuts+"=>"oooo");  
$k = array_rand($sites);  
echo $k."\n";
$sites[$k]; 
...
view (7 lines, 2 lines of output)
PHP, pasted on Sep 17:
1
2
3
4
5
<?php
$sites = array("Nettuts+", "Psdtuts+", "Mobiletuts+", "Mactuts+");  
$k = array_rand($sites);  
$sites[$k]; 
echo  $sites[$k]; 
...
view (6 lines, 1 line of output)
PHP, pasted on Sep 7:
1
2
3
4
5
<?php
// Delimiters may be slash, dot, or hyphen
$date = "04.30.1973";
list($month, $day, $year) = split('[/.-]', $date);
echo "Month: $month; Day: $day; Year: $year<br />\n";
...
view (8 lines, 9 lines of output)
PHP, pasted on Sep 6:
1
2
3
<?php
echo metaphone("pearl");
?>
view (3 lines, 1 line of output)
PHP, pasted on Sep 6:
1
2
3
4
<?php
$date = time();
echo $date;
?>
view (4 lines, 1 line of output)
PHP, pasted on Sep 6:
1
2
3
4
5
<?php
//facebook like past time display
function facebook_style_date_time($timestamp){
$difference = time() - $timestamp;
$periods = array("sec", "min", "hour", "day", "week", "month", "years", "decade");
...
view (24 lines, 1 line of output)
PHP, pasted on Sep 6:
1
2
3
4
5
<?php
function facebook_style_date_time($timestamp){
$difference = time() - $timestamp;
$periods = array("sec", "min", "hour", "day", "week", "month", "years", "decade");
$lengths = array("60","60","24","7","4.35","12","10");
...
view (23 lines, 1 line of output)
PHP, pasted on Jul 24:
1
2
3
4
5
<?php

$timezone="Asia/Calcutta";
date_default_timezone_set($timezone);
echo date('y-D-M h:i:s');
...
view (6 lines, 1 line of output)
PHP, pasted on Jul 24:
1
2
3
4
5
<?php
date_default_timezone_set('Asia/Delhi');

$timestamp = strtotime("+1 month +2 days +0 hours +0 minutes 2 seconds")."\n";
echo $timestamp;
...
view (7 lines, 2 lines of output)
PHP, pasted on Jul 24:
1
2
3
4
5
<?php
$timestamp = strtotime("+1 month +2 days +4 hours +32 minutes 2 seconds")."\n";
echo $timestamp;
echo date('y-D-M h:i:s', $timestamp);
?>
view (5 lines, 2 lines of output)
PHP, pasted on Apr 9:
1
2
3
4
5
<?php
$my_array = array("Dog","Cat",45,'f');
var_dump($my_array);
echo "\n";
var_export($my_array);
...
view (11 lines, 24 lines of output)
PHP, pasted on Apr 2:
1
2
3
4
5
<?php
    function some_func($a, $b) {
        for ($i = 0; $i < func_num_args(); ++$i) {
            $param = func_get_arg($i);
            echo "Received parameter $param.\n";
...
view (17 lines, 9 lines of output)
PHP, pasted on Apr 2:
1
2
3
4
5
<?php

class Teste {

    function insertUser() {
...
view (74 lines, 12 lines of output)
PHP, pasted on Apr 2:
1
2
3
4
5
<?php

class Teste {

    function insertUser() {
...
view (74 lines, 12 lines of output)
PHP, pasted on Mar 28:
1
2
3
4
5
<?php
$var = array("naMe"=>"madhu","desTination"=>"developer");
print_r(array_change_key_case($var,CASE_UPPER));
print_r(array_change_key_case($var,CASE_LOWER));
?>
view (5 lines, 10 lines of output)
PHP, pasted on Mar 17:
1
2
3
4
<?php
$test = array ('first'=>'balaji','second'=>'balaji2','third'=>'balaji3');
print_r(array_chunk($test,2));
?>
view (4 lines, 14 lines of output)
PHP, pasted on Dec 10:
1
2
3
4
5
<?php
$array = array("2011-September_38","2011-September_10","2010-November_1","2011-June_50","2011-June_4","2009-November_9","2009-November_29","2010-December_19","2011-September_1");
function monthCompare($a, $b) {
   $count = substr($a,strpos($a,'_'));
   $count =strlen($count);
...
view (36 lines, 6 lines of output)
PHP, pasted on Dec 3:
1
2
3
4
5
<?php
$array = array("2011-September_38","2011-September_10","2011-June_50","2011-June_4","2009-November_9","2009-November_29","2010-December_19","2011-September_1");
function monthCompare($a, $b) {
   $count = substr($a,strpos($a,'_'));
   $count =strlen($count);
...
view (36 lines, 6 lines of output)
PHP, pasted on Dec 3:
1
2
3
4
5
<?php
$array = array("2011-September_38","2011-June_4","2009-May_3","2009-May_45","2010-March_2","2010-November_9","2011-December_29","2010-March_19");
function yearmonthCompare($a, $b) {
   $count = substr($a,strpos($a,'_'));
   $count =strlen($count);
...
view (19 lines, 51 lines of output)
PHP, pasted on Dec 2:
1
2
3
4
5
<?php
$array = array("2011-September_38","2011-June_4","2009-May_45","2010-November_9","2011-December_29","2010-March_19");
function monthCompare($a, $b) {
   $count = substr($a,strpos($a,'_'));
   $count =strlen($count);
...
view (14 lines, 9 lines of output)
PHP, pasted on Dec 2:
1
2
3
4
5
<?php
$array = array("2011-September_38","2011-June_4","2010-November_9","2011-November_29","2010-December_19");
function monthCompare($a, $b) {
   $count = substr($a,strpos($a,'_'));
   $count =strlen($count);
...
view (14 lines, 8 lines of output)
PHP, pasted on Dec 2:
1
2
3
4
5
<?php
$range = range(2011,2100);
$range = array_flip($range);
print_r($range);
?>
view (5 lines, 93 lines of output)
PHP, pasted on Dec 1:
1
2
3
4
5
<?php
$array = array("2011-September_38","2011-June_4","2011-November_9");
function monthCompare($a, $b) {
    $a = strtolower(substr($a,5,-3));
    $b = strtolower(substr($b,5,-3));
...
view (29 lines, 10 lines of output)
PHP, pasted on Dec 1:
1
2
3
4
5
<?php
    $date=array('2009-03','2010-01','2009-02');
    for ($i=0;isset($date[$i]);$i++) {

    $datess=explode('-',$date[$i]);
...
view (12 lines, 6 lines of output)
PHP, pasted on Dec 1:
1
2
3
4
5
<?php
    $date=array('2009-03','2010-01','2009-02');
    for ($i=0;isset($date[$i]);$i++) {

    $datess=explode('-',$date[$i]);
...
view (12 lines, 6 lines of output)
PHP, pasted on Dec 1:
1
2
3
4
<?php
    $date=array('2009-03','2010-01','2009-02');
    for ($i=0;isset($date[$i]);$i++) {
    $datess=explode('-',$date[$i]);
...
view (10 lines, 6 lines of output)
PHP, pasted on Dec 1:
1
2
3
4
5
<?php
    //set date array to list of dates in y-d-m format
    $date=array('2009-03','2010-01','2009-02');
    for ($i=0;isset($date[$i]);$i++) {
    $datess=explode('-',$date[$i]);
...
view (18 lines, 6 lines of output)
PHP, pasted on Dec 1:
1
2
3
4
5
<?php
function sortMonths($a1, $b1) {
	$a = date("Y F",$a1);
	$b = date("Y F",$b1);	
    if ($a->received_date == $b->received_date)
...
view (17 lines, 1 line of output)
PHP, pasted on Dec 1:
1
2
3
4
5
<?php 
//convert timestamp to normal date
$test=array(1316427274,1289909504);
foreach($test as $sort)
{
...
view (14 lines, 5 lines of output)
PHP, pasted on Dec 1:
1
2
3
4
<?php 
//convert timestamp to normal date
echo date("Y F d H:i:s a","1316427274");
?>
view (4 lines, 1 line of output)
PHP, pasted on Nov 17:
1
2
3
4
5
<?php
//merge two arrays
$array1 = array("color" => "red", 2, 4);
$array2 = array("a", "b", "color" => "green", "shape" => "trapezoid", 4);
$result = array_merge($array1, $array2);
...
view (7 lines, 10 lines of output)