JQuery code to append html using div id

Here am going to show you JQuery code to append html using div id
suppose i have html code like below i need append a text content to the html area when user entering any text

 

<input type="text" value="" id="inputarea">

<div id="html_area">

</div>

 

$(document).ready(function(){
$("#inputarea").blur(function(){
  $("#html_areap").append("<b>User Is typing a text</b>");
});
});

PHP code to find the current year,current month and current day

PHP have date function get all the information related to date here we have to search find out PHP code to find the current year,current month and current day , current year,current month and current day can be easily find out using date() function let me check how to do it

php code to find current year


<?php

echo date('Y');  //Capital Letter Y

Out Put

2019

?>

<?php

echo date('y');  //Small letter y

Out Put

19

?>

php code to find current month


<?php

 echo date('M');  

Out Put

Jul

?>

<?php

 echo date('m');  

Out Put

07

?>

php code to find current day

 


<?php

 echo date('D');  

Out Put

Mon

?>

<?php

 echo date('d');  

Out Put

08

?>

php try catch exception handling code with example

Here we are try to find out how to add php try catch exception handling code in your PHP function .we know that like every programming language php also as its on error handling method, Exception handling in PHP ,new object oriented way of dealing with errors, is so easy we have have PHP try catch exception handling code here we hvae syntax

//trigger exception in a "try" block
try {

}
//catch exception
catch(Exception $e) {
  echo 'Error: ' .$e->getMessage();
}

See PHP try catch exception handling code with example


try {
          $status = 1;

            $cont = $this->conn;
            $sql = "INSERTED INTO menu(display_name, menu_link,  status,sort_order,menu_slug) VALUES(:menu_title,:menu_link,:status,:sort_order,:menu_slug)";
            $new_db = $cont->prepare($sql);

            $new_db->bindParam(':menu_title', $data['menu_title']);
            $new_db->bindParam(':menu_link', $data['menu_link']);

            $new_db->bindParam(':sort_order', $data['sort_order']);
            $new_db->bindParam(':status', $status);
            if($data['menu_slug']!='')
            {
                $slug_value=$data['menu_slug'];
            }
            else
            {
                $slug_value=$data['menu_title'];
            }
            $slug = $this->generate_sub_menu_slug($extra_string='',$slug_value);
            $new_db->bindParam(':menu_slug', $slug);


            $new_db->execute();
        } catch (PDOException $e) {
            echo "Error: " . $e->getMessage();
        }

In the above example MySQL INSERT syntax is wrong so this php code through an Exception error that says SQL state error

 try { 
          $status = 1;

            $cont = $this->conn;
            $sql = "INSERT INTO menu(display_name, menu_link,  status,sort_order,menu_slug) VALUES(:menu_title,:menu_link,:status,:sort_order,:menu_slug)";
            $new_db = $cont->prepare($sql);

            $new_db->bindParam(':menu_title', $data['menu_title']);
            $new_db->bindParam(':menu_link', $data['menu_link']);

            $new_db->bindParam(':sort_order', $data['sort_order']);
            $new_db->bindParam(':status', $status);
            if($data['menu_slug']!='')
            {
                $slug_value=$data['menu_slug'];
            }
            else
            {
                $slug_value=$data['menu_title'];
            }
            $slug = $this->generate_sub_menu_slug($extra_string='',$slug_value);
            $new_db->bindParam(':menu_slug', $slug);


            $new_db->execute();
        } catch (PDOException $e) {
            echo "Error: " . $e->getMessage();
        }

How to read a file content line by line using PHP code

Suppose we have file named file.txt we have read a file content line by line using PHP , here our objective is to retrieve a file data line by line using PHP.we know we have most famous php function fopen(“File name”,”r”),it will read entire content from the files and store it in the defined variable
see example

 $f_data = fopen("file.txt","r");
 

Now our question how to read line by line using PHP
Now we know the entire data is their in $f_data,next we have to read line by line using PHP , with the help of while loop we can do that ,for line by line read we use one more function called feof($f_data) which find out the end of the file see full example

 
 $f_data = fopen("file.txt","r");
  
  while(! feof($f_data))  {
	$result = fgets($f_data);
	echo $result."
"; echo "Good"."
"; } fclose($f_data);

e.g
file.txt

Sunday is weekend day
Monday is weekstart day

Out Put

Sunday is weekend day
Good
Monday is weekstart day
Good