Friday, May 25, 2012

most important php function

<?php
Top Most important Php 
function 

1.  empty(); // return true false 
$p='val';

if(!empty(
$p)){ // if $p is not empty 
echo 'variable is not empty ';
} else {
 echo 
'value is null';
}


2. unset();

use for 
unse session or variable values 
unset($a);

3. isset();

if(isset(
$a)){

echo 
'value is set ';
} else {  
echo 
'value is not set ';
}

4. trim()

use for 
removes the whitespaces from the left part of the string.
trim($a);

5. explode () ;

convert strin to array 
$str "Rajeev Dhar dwivedi"; $array explode(" ",$str); print_r($array);
outPut :

Array ( [
0] => Rajeev [1] => Dhar [2] => dwivedi )


6. implode(); convert array to string 

$array 
= array( 'Rajeev' ,'Dhar','Dwived') ;

echo 
implode(" ",$array);
Output Rajeev Dhar Dwived


7. date
() function 
this function use fot get date from system
echo date('Y-M-d');


8. time() 

this function use for get time from system in mili second 
echo time(); 

9. strip_tags();



use for remove html tags 


example :
$tag="<b><p>rajeev</p></b>";


  echo strip_tags($tag);  // output : rajeev



 this is   most important php functions  .

php functions list


this is predefine php function and very important function 





Wednesday, May 23, 2012

export data as excel format from php mysql

<?php
$file
="marksreport".$_POST["txtfromdate"].".xls";


header('Content-Type: text/html'); 

header("Content-type: application/x-msexcel"); 

//tried adding  charset='utf-8' into header

header("Content-Disposition: attachment; filename=$file"); ?>


copy and paste into header in page 

export to excel from project

Monday, May 21, 2012

display column values as rows in mysql query

id c1 c2 c3
1 10 20 30
2 15 50 24
SELECT 'C1' as colname, c1 as colval FROM `tablename`
UNION ALL SELECT 'C2' as colname , c2 AS colval FROM `tablename`
UNION ALL SELECT 'C3' as colname , c3 AS colval FROM `tablename`

C1 10
c1 15
c2 20
c2 50
c3 30
c3 24


display column values as rows wise




union operation in mysql


1. NUMBER OF COLUMN IS SAME 

2. DATA TYPE IS SAME BUT NOT NECESSARY IN MYSQL 

SELECT *   FROM `table1`

 UNION

 SELECT *  FROM `table2`  LIMIT 0 , 30

Friday, May 11, 2012

string replace in php

<?php

$str 
"My Name Is INPLACE ";
$str=str_replace("INPLACE","Rajeev",$str);
echo 
$str ;


// output : My Name Is Rajeev 

Friday, May 4, 2012

Widgets Development in wordpress

function.php

copy and past in function.php page , you can also development more widgets area using this function
<?php
function add_widgets_init() {

    
register_sidebar( array(
        
'id' => 'first-sidebar',
        
'name' => __'First Sidebar' 'buttercream' ),
        
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
        
'after_widget' => '</aside>',
        
'before_title' => '<h2 class="widget-title">',
        
'after_title' => '</h2>'
        
)
    );

    
register_sidebar( array(
        
'id' => 'second-sidebar',
        
'name' => __'Second Sidebar' 'buttercream' ),
        
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
        
'after_widget' => '</aside>',
        
'before_title' => '<h2 class="widget-title">',
        
'after_title' => '</h2>'
        
)
    );

    
register_sidebar( array(
        
'id' => 'third-sidebar',
        
'name' => __'Third Sidebar' 'buttercream' ),
        
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
        
'after_widget' => '</aside>',
        
'before_title' => '<h2 class="widget-title">',
        
'after_title' => '</h2>'
        
)
    );
}
add_action'widgets_init''add_widgets_init' );  // initilization
?>


sidebar.php

copy and paste in sidebar.php page or any where you want to see your widgets
<?php do_action'before_sidebar' ); ?> 
 <?php if ( ! dynamic_sidebar__'First Sidebar' 'buttercream' ) ) ) : ?> 
<?php endif; // end First sidebar widget area ?>             
  



<?php do_action'before_sidebar' ); ?> 
<?php if ( ! dynamic_sidebar__'second-sidebar' 'buttercream' ) ) ) : ?>  
<?php endif; // end second sidebar widget area ?>        
     
            
 <?php do_action'before_sidebar' ); ?>  

<?php if ( ! dynamic_sidebar__'Third Sidebar' 'buttercream' ) ) ) : ?> 
<?php endif; // end third sidebar widget area ?>