<?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.
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 past into header in page
export to excel from project
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 |
what is wordpress
wordpress is one of the most popular CMS . there are many website is development in Word press .
wordpress is very simple to use . you can create category , post , pages and image library in this cms . if you want to use some thing extra in wordpress it possible using plunging . pluggin is most powerful feature of wordpress. widgets is another method in wordpress .
top MNC company work in php
there are many top MNC company is work in php . such as
TCS
IBM
there are many scope in php in India. i think if you want to get more money in php them you learn MVC framework . a website developer must be know any CMS and Framework
string replace in php
<?php
$str
= "My Name Is INPLACE ";
$str=str_replace("INPLACE","Rajeev",$str);
echo $str ;
// output : My Name Is Rajeev
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 ?>
syllabus of PHP
Add more Input box using javascript
function addvalue(){ var products=””; var i=$(“#tblproduct tr”).size(); var j=0; var str=””; var k=0; for(j=1;j<=i;j++) { proval=""; proqty=""; if($("#txtpro"+j).val()!='0' && $("#qty"+j).val()!='') { str+="&pro"+j+"="+$("#txtpro"+j).val()+"&qty"+j+"="+$("#qty"+j).val(); k++; } } alert(str); /* $.ajax({ type: 'POST', url: "data.php?id="+i+'&str='+str, data: {}, success: function(data){ alert(data); } }); */ } function btnclickadd() { var i = $('#tblproduct tr').size() +1; $(".addmore").hide(); $('#myid').val(i); var x="”; x=x.replace(‘txtpro1’,’txtpro’+i).replace(‘txtpro1’,’txtpro’+i); $(‘
‘).appendTo(‘#tblproduct’); return false; }
Product: | Quantity: | Add More |
list of table and database in php mysql
<?php
$con = mysql_connect('localhost' , 'root' ,'');
mysql_select_db('demo' , $con );
$sql = "SHOW TABLES FROM demo";
$result = mysql_query($sql);
echo
' Total Table = ' . mysql_num_rows($result);
// list of table in database
while ($row = mysql_fetch_row($result)) {
echo "<br> {$row[0]}\n";
}
mysql_free_result($result);
?>
<?php
// list of database
$dblist = mysql_query("SHOW DATABASES");
echo '<br> Total Database :'. mysql_num_rows($dblist) . '<br> ';
while ($row = mysql_fetch_assoc($dblist)) {
echo $row['Database'] . "<br>";
}