How to enable PHP mail function on Ubuntu

Here are steps to follow:

First of all install packagephp-pear if it’s already not installed. apt-get install php-pear
Then install following PEAR packages

  • pear install mail
  • pear install Net_SMTP
  • pear install Auth_SASL
  • pear install mail_mime

Then install POSTFIX

apt-get install postfix

This command will bring dialogue step by step to setup mail server.

Select Internet Site

and choose domain mail to be sent from

Try to send mail using mail() function, and you’ll receive the one you sent.

Anonymous function example in PHP

 

  1. <?php
  2.  
  3. /**
  4. * An array function to work with its individual value whatever we want.
  5. * @param array $array
  6. * @param function $function
  7. */
  8. function anonymous_test($array, $function){
  9. foreach ($array as $single){
  10. $function($single);
  11. }
  12. }
  13. ?>

 

 

  1. <?php
  2. /**
  3. * Here we are writing a function which will print only if it's printable.
  4. */
  5. $arr = [1,2,3,['A','B'],4,5];
  6. anonymous_test($arr, function($value){
  7. if(!is_array($value) && !is_object($value)){
  8. echo $value;
  9. }
  10. });

Add Remove row using jQuery

jQuery Code:

  1. jQuery(document).ready(function () {
  2. /*
  3.   * Give an attribute to anchor tag 'js-add' and the value of that attribute
  4.   * to be his parent selector which is to be copied and to be added after it.
  5.   * For example if you provide <a js-add=".js-field_row">text</a>
  6.   * On click of this element will copy its parent element having class js-field_row
  7.   * and will after it.
  8.   * */
  9. jQuery(document).on('click', 'a[js-add]', function () {
  10. var element_to_clone_selector = jQuery(this).attr('js-add');
  11. var element_to_clone = jQuery(this).parents(element_to_clone_selector);
  12. var duplicate_element = element_to_clone.clone();
  13. element_to_clone.after(duplicate_element);
  14. });
  15.  
  16. /*
  17.   * Give an attribute to anchor tag 'js-remove' and the value of that attribute
  18.   * to be his parent selector which is to be deleted.
  19.   * For example if you provide <a js-remove=".js-field_row">text</a>
  20.   * On click of this element will remove its parent element having class js-field_row
  21.   * */
  22. jQuery(document).on('click', 'a[js-remove]', function () {
  23. var removable_element_selector = jQuery(this).attr('js-remove');
  24. var removable_element = jQuery(this).parents(removable_element_selector);
  25. //count all siblings, if its more than 1, delete the selected element.
  26. var total_row = removable_element.siblings(removable_element_selector).length;
  27. if (total_row > 0) {
  28. removable_element.remove();
  29. } else {
  30. alert('There should be at least one row');
  31. }
  32. });
  33.  
  34. });

 

Add two buttons inside the row to add and remove the row like:

<a class="btn btn-success" js-add=".js-field_row">+</a>
<a class="btn btn-danger" js-remove=".js-field_row">-</a>

Inside js-add and js-remove attribute of the buttons add the selector of the row. For example if you want to add/ remove row on the basis of class add .class_name
.

HTML Code example:

  1. <div class="row table-striped form-group js-field_row">
  2. <div class="col-sm-3">
  3. <div class="form-group field-templatemeta-field_name required">
  4. <label class="control-label" for="templatemeta-field_name">Field Name</label>
  5. <input type="text" id="templatemeta-field_name" class="form-control" name="TemplateMeta[field_name][]" maxlength="25">
  6.  
  7. <div class="help-block"></div>
  8. </div> </div>
  9. <div class="col-sm-3">
  10. </div>
  11. <div class="col-sm-1">
  12. </div>
  13. <div class="col-sm-3 js-field_value_col">
  14. <div class="form-group field-templatemeta-field_value">
  15. <label class="control-label" for="templatemeta-field_value">Field Value</label>
  16. <input type="hidden" id="templatemeta-field_value" class="js-field_value" name="TemplateMeta[field_value][]">
  17.  
  18. </div>
  19. </div>
  20. <div class="col-sm-2 pull-right">
  21. <label>&nbsp;</label><br>
  22. <a class="btn btn-success" js-add=".js-field_row">+</a>
  23. <a class="btn btn-danger" js-remove=".js-field_row">-</a>
  24. </div>
  25. </div>

 

list of modes for fopen in php

 

 

Mode Read Write Pointer at Truncate to zero create new
r y n beginning of the file n n
r+ y y beginning of the file n n
w n y beginning of the file y If it does not exist
w+ y y beginning of the file y If it does not exist
a n y end of the file n If it does not exist
a+ y y end of the file n If it does not exist
x n y beginning of the file not rquired always
x+ y y beginning of the file not required always
c n y beginning of the file n If it does not exist
c+ y y beginning of the file n If it does not exist

difference between timestamp and datetime in mysql

Often you get confused while going to build a schema for your application to use datetime or timestamp as a datatype in a table field. Here is the detail for ‘difference between timestamp and datetime in mysql’ in tabular format which will be easy to understand the differences.:

 

DATETIME TIMESTAMP
The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59' TIMESTAMP has a range of '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC.
MySQL retrieves and displays DATETIME values in 'YYYY-MM-DD HH:MM:SS'format.
With the fractional part included, the format for these values is 'YYYY-MM-DD HH:MM:SS[.fraction]', the range for DATETIME values is '1000-01-01 00:00:00.000000' to '9999-12-31 23:59:59.999999' With the fractional part included, the format for these values is 'YYYY-MM-DD HH:MM:SS[.fraction]', the range for TIMESTAMP values is '1970-01-01 00:00:01.000000' to '2038-01-19 03:14:07.999999'
MySQL doesn’t converts DATETIME values, it stores it as you have provide, and gives back as you have provided. MySQL converts TIMESTAMP values from the current time zone to UTC for storage, and back from UTC to the current time zone for retrieval
Invalid values will be converted to 0 like ‘0000-00-00 00:00:00’
MySQL does not accept TIMESTAMP values that include a zero in the day or month column or values that are not a valid date.for example '0000-00-00 00:00:00'
TIMESTAMP and DATETIME columns can be automatically initializated and updated to the current date and time (that is, the current timestamp).
If both (DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP) are present in a column definition, either can occur first.
Any of the synonyms ( CURRENT_TIMESTAMP(), NOW(), LOCALTIME, LOCALTIME(), LOCALTIMESTAMP, and LOCALTIMESTAMP()) for CURRENT_TIMESTAMP have the same meaning as CURRENT_TIMESTAMP.

1 of 812345678