Posts

Showing posts with the label explode function in php

export to excel in php

Image
Hi friends Excel files are great for many things. It might though be a little bit tricky to generate them on the fly with php. Therefor I will guide you exactly how to do it, quick and simple. Excel is a very useful format for lots of purposes. For example, exporting stats, member lists to hand over to economy department etc.   <?php echo "Export Data Using PHP"; echo ' <form action="'. $phpself.'"> '; echo '<input name="submit" type="submit" value="Export" /> </form> '; ?> } else { $dbc = mysql_connect("localhost","root",""); mysql_select_db("test",$dbc); $contents="ID,Title,Visit\n"; $user_query = mysql_query('select id,title,visit from wallpaper'); while($row = mysql_fetch_array($user_query)) { $contents.=$row[0].","; $contents.=$row[1].","; $contents.=$row[2]."\n"; } ...

get time difference in php

Image
Date and time is one function which is always like there in whatever website, project you create. The more simple they look like to start with the more complex they become. Complexity comes in when we put these functions into different loops conditions etc.  The line below show you how you can call function. The function expects to be given 2 strings representing the start and end values of a time or date. <?php echo 'Hi! My name is Ankit Kumar Chauhan. I am: '.getDifference(date("Y-m-d G:i:s"),'1985-10-02 00:00:00'). ' Years old.'; function getDifference($startDate,$endDate,$format = 6) {     list($date,$time) = explode(' ',$endDate);     $startdate = explode("-",$date);     $starttime = explode(":",$time);     list($date,$time) = explode(' ',$startDate);     $enddate = explode("-",$date);     $endtime = explode(":",$time);     $secondsDifference = mktime(...

how to use explode function in php

Here is the example to use explode function on an array fetched from database values separated by comma ( , ) and count duplicate values also. First create database " your database" and a table named "blog". Enter some data a:- For first row- insert following data---   Ankit, Om For second row- insert following data---   Ankit, Ajeet, Santosh. After that create a php page and paste following coding and change username, password and database name . <table cellpadding="0" cellspacing="0" class="backcolor" style="border: 1px solid rgb(204, 204, 204);"> <?php mysql_connect('localhost','Username','Password'); mysql_select_db('database_name'); $sql = "select tag from blog"; $result = mysql_query($sql)or die('Error in get blog detail'.mysql_error()); $toTagArray = array(); $i=0; while($tag = mysql_fetch_row($result)){ $TagArray = explode(",", $tag[0]); ...