Skip to main content

Posts

Date formats in php

Sometimes we need to display date in our comment , post , news etc. For that as you aware we need to store that date in our database , the format of date in database is Y M D. But that might be possible in some cases we need to display the date in different format. One simple way for that is explode the date which is come from database by "-" and set according to your requirement. But what happen when we want to display date in different format like 1 jan 2011 01 january  2011 01 january 11 etc... The solution is  strtotime . To display simple date in php echo date("Y-m-d"); but when date comes from database at that time use : date("j M Y ", strtotime( Here date comes form database  )); j M Y is different types of format ..More formats are display below :: Day d : Day of the month with leading zeroes. Values are 01 through 31. j : Day of the month without leading zeroes. Values 1 through 31 D : Day of the week abbreviations. ...

BSNL tablet gets over one lakh pre order requests

Public sector telecom operator, BSNL, which recently launched extremely low cost tablets along with two mid range tablets, has got a tremendous response from Indian consumers. The three tablets, bundled with its connection, are in the price range of Rs 3,499 - Rs 12,500. They are manufactured by Noida based Pantel Technologies. Virendra Singh, managing director of Pantel Technologies, said to The Mobile Indian, "We have received more than one lakh pre booking orders over phone and online for the three tablets which we have launched in association with BSNL." He further added, "Apart from the consumers' interest, we have also got an order for two lakh tablets from Sahara India." The entry level BSNL tablet, Penta IS701R, is a WiFi only device with Android 2.3 operating system, 1 GHz processor and 256 MB RAM. The tablet also has an HDMI port through which it can be connected to a TV. Its 7 inch resistive touchscreen has 800 x 600 pixel resolution and 16:9 asp...

Find extension of file in Php

In our scripting sometimes we need to upload such documents , at that time there should be a validation for proper file. For example in your system suppose there is a field for image upload , that is obvious in that field only image formats are allowed (jpg,jpeg,png,gif etc.). At that time you have to give a validation on that field. In Php to find the extension and validation here is your code :  <?php                     $image = $_FILES["file"]["name"];    // to fetch the file name             $n1=strripos($image,".");                     // to find the last position of "."             $v1 =substr($image,$n1);                  ...

Find extension of file in Javascript

In our scripting sometimes we need to upload such documents , at that time there should be a validation for proper file. For example in your system suppose there is a field for image upload , that is obvious in that field only image formats are allowed (jpg,jpeg,png,gif etc.). At that time you have to give a validation on that field. In javascript to find the extension and validation here is your code :  <script type="text/javascript">       var str = document.form1.file.value.toLowerCase();                                  // to convert the value in lower case       var split = str.split(".");     // split the value by "."       var s =split.length;          // find the length       var ext = (split[s-1]);   ...

Use of indexOf and charAt in javascript

indexOf(): The indexOf() method returns the position of the first occurrence of a specified value in a string. This method returns -1 if the value to search for never occurs. example :  <script type="text/javascript"> var str="Hello world!"; document.write(str.indexOf("d") + "<br />"); document.write(str.indexOf("WORLD") + "<br />"); document.write(str.indexOf("world")); </script> Output : 10 -1 6 charAt() The charAt() method returns the character at the specified index in a string. The index of the first character is 0, and the index of the last character in a string called "txt", is txt.length-1 <script type="text/javascript"> var str = "Hello world!"; document.write("First character: " + str.charAt(0) + "<br />"); document.write("Last character: " + str.charAt(str.l...

Find the difference between array

Sometimes we need to find the difference between arrays In php there is a inbuilt function to find the difference between array. For example : <?php $a1=array(0=>"Apple",1=>"Honda",2=>"Scoda"); $a2=array(3=>"Scoda",4=>"Honda",5=>"Ford"); print_r(array_diff($a1,$a2)); ?>  The output of the code above will be:  Array ( [0] => Apple ) 

Difference between == and === in php

Two of the many comparison operators used by PHP are '==' (i.e. equal) and '===' (i.e. identical). The difference between the two is that '==' should be used to check if the values of the two operands are equal or not. On the other hand, '===' checks the values as well as the type of operands. Let me explain more using some examples: '==' (Equal): if("22" == 22) echo "YES"; else echo "NO";      The code above will print "YES". The reason is that the values of the operands are equal. Whereas when we run the example code below: '===' (Identical): if("22" === 22) echo "YES"; else echo "NO"; The result we get is "NO". The reason is that although values of both operands are same their types are different, "22" (with quotes) is a string while 22 (w/o quotes) is an integer. But if we change the code above to t...