Php Examples with Source code and output

Learn something about PHP.

Php is Hypertext Preprocessor is widely used for server side script language. Is embedded in HTML (hypertext markup language). Php Examples with Source code and output. Php is open source is server side script language or used as a General-Purpose Programming Language and PHP is an interpreter that is freely available. Commonly PHP is open source. And PHP programming is very easy to learn PHP beginners.

Php is script language run on a server, with the help of PHP you can create static, dynamic web pages.

Php examples with source code and output

Php codes starting with <?php and end ?> tag. For example, how can represent Php programming with starting and end tag? To continue our programming part let’s take an example, first we declare basic part of programming – 

<!DOCTYPE html>

<html>

<head>

<title>Star Academy</title>

</head>

<body>

<?php

echo “Hey! Your are watching Star Academy Educational Website.“;

?>

</body>

</html>

Output:-

Hey! Your are watching Star Academy Educational Website.

 

About the Tags :-

In this tutorial, you learn about Php example with source code and output. In this code first known about Tags like  <!DOCTYPE html> is denoted HTML 5 & define document type, our second tag <html> defines an HTML document, next is define information about the document in the top of browser with the help of <tilte> tag, next tag<body> tag is define our website body if you want to create something in the website you create in the body, and other tags are like as- <p>tag is paragraph tag, <h1>to <h6> are heading tag is used in the website paragraph highlight any paragraph, <br> tag are break tag is using break the paragraph, <!–……..–> is define comment when have do some coding and you want to declare some comment in the relative world or to understanding & rememmbering in the programming then you can easily use comment tag. See below Php Examples with Source code and output

How can use Heading <h>tag in the Programming?

<!DOCTYPE html>

<html>

<head>

<title>Star Academy</title>

</head>

<body>

<h1>Hey! this is my syntax.</h1>

<?php

echo “Hello world.“;

?>

</body>

</html>

Output:-

Hey! this is my syntax.

Hello world.

How Can represent a comment in the programming?

<!DOCTYPE html>

<html>

<head>

<title>Star Academy</title>

</head>

<body>

<h1>Hey! How can using comments in the programming.</h1>

/* This is your comment you can easy to learn comment(multi line comment)*/

<?php

echo “Hello world.“;    //This is single line comment.

?>

</body>

</html>

Output:-

Hey! How can using comments in the programming.

Hello world.

Using javascript in your programming:-

First, you want to know that what is javascript and why are using javascript in the programming?

Javascript is dynamic computer programming language. It is lightweight and most commonly used as a part of web pages, whose implementation allow client-side-script to interact with the user and make dynamic pages. It is an interpreted programming language with object-oriented capabilities. Brendan Eich created javascript in 1995.

Client-side javascript is the most common form of the language. The script should be included in or referenced by an HTML document for the code to be interpreted by the browser.

Uses of javascript:-

Javascript is a scripting language, it is used for commonly programming language to creating interactive effective web pages and integrated with HTML. Most called for client-side-script development language. With the help of javascript and you can change your web pages like that if you want to do make your site mobile responsive then you can use javascript and make a mobile responsive website or pages, and with the help of javascript. 

Javascript use in many places like as many server programs uses javascript, many databases like MongoDB and more use javascript in our programming, web pages using javascript.

Difference between Java & Javascript:-

Both are some similar and useful to programmers, but both are some major difference, java is the programming language. It is used for making a biggest software, applications,games etc., javascript is server-side-script language. It is client side. It is run on the browser and it is object oriented.

Generally javascript using for creating some attraction in the pages. Let’s take an example how can create a changes and how can create a java script pages.

Some limitation of JavaScript:-

There are some limitation of the JavaScript are blow :-

  1. Client-side javascript does not allow the reading or writting of files. This has been kept for security reason.
  2. Javascript cannot be used for networking applications.
  3. Javascript does’t have any multithreading or multiprocessor capabilities.

Advantages of javascript:-

  • Less server interaction :-You can validate user input before sending the page off to the server. This saves server traffic, which means less load on your server.
  • Immedate feedback to the visitors :- They don’t have to wait for a page reload to see if they have forgotten to enter something.
  • Increased interactivity:- You can create interfoces that react when the user hovers over them with a mouse or activates them via the keyboard.

You have a two option to perform your js part in the web pages :-

(1.)  Extranal pages     (2.) In-line

(1.)  Extranal Page:-:- 

Let’s take an example how can represent  In-page/External page JavaScript function.

<!DOCTYPE html>

<html>

<head>

<title>Star Academy</title>

<script>

<script src=”script.js”>

</script>

</head>

<body>

</body>

</html>

(2.) In-Line:-

Example (1):-

<!DOCTYPE html>

<html>

<head>

<title>Star Academy</title>

</head>

<body>

<h3>This is example define In-line pages javascript.</h3>

<button type=”button” onclick=”document.getElementById(‘demoexp’).innerHTML=Date()”>Show Date & Time</button>

<p id=”demoexp”></p>

</body>

</html>

Output:-

This is example define In-line pages javascript.

When you click show Date & Time button and display

            29/8/2018 9.15:00

Example (2):-

<!DOCTYPE html>

<html>

<head>

<title>Star Academy</title>

<script>

function  para(){

document.getElementById(“demopreview”.innerHTML=”Hello Dear! “;

}

</script>

</head>

<body>

<p id=”demopreview”>Welcome Our Pages.</p>

<button type=”button” onclick=”para()”>Click Me </button>

</body>

</html>

Output:-

Welcome Our Pages

When you click this button then priview this answer :-

Hello Dear!

 

How can represent javascript self Executing Anonymous function with alert :-

<!DOCTYPE html>
<html>
<head>
<script>

// JavaScript self Executing Anonymous function

(function() {

alert(“Auto show up message.”)

})();
</script>
</head>
<body>

</body>
</html>

Output:-

In the example, you see an alert pop up box alert the message.

Again if you want to do alternate syntax display then you have only some changes in the programming only you can add one function and you have received two alerts in the browser. 

For Example:-

<!DOCTYPE html>
<html>
<head>
<script>

// JavaScript self Executing Anonymous function

(function() {

alert(“Auto show up message.”)

})();

// alternate syntax

(function() {

alert(“Auto show up message 2.”)

})();

</script>
</head>
<body>

</body>
</html>

Output:-

And then you click the OK button then you have received next pop up alert.

 

 

 If you want to pass the argument to a self-executing function, let’s begin with help of an example of programming.

For Example:-

<!DOCTYPE html>
<html>
<head>
<script>

// Pass argument to self executing function

(function(x,y){
alert(“sum of x & y: ” + (x + y));
})(10, 20);

</script>
</head>
<body>

</body>
</html>

Output:-

sum of x & y: 30

OK

 

 If you want to self executing function with return, let’s begin with help of an example of programming.

For Example:-

<!DOCTYPE html>
<html>
<head>
<script>

//self executing function with return

var Sum = (function(x,y){

return (x + y);

})(10,50);

alert(“Returned Sum:” + Sum);

</script>
</head>
<body>

</body>
</html>

Output:-

Returned Sum: 60

OK

 

 If you want to window object  print  using  global variable then you have simple code, let’s begin with help of an example of programming.

For Example:-

<!DOCTYPE html>
<html>
<head>
<script>

// window object  print code

// using  global variable

var x = 15;
alert(window.x);

</script>
</head>
<body>

</body>
</html>

Output:-

15

OK

 

 If you want to window object  print  using  global variable in the help of Global function invoked using window object, then you have simple code, let’s begin with help of an example of programming.

For Example:-

<!DOCTYPE html>
<html>
<head>
<script>

//-window object

// global variable

var x = 15;

function y(){
document.write(“Global function invoked using window object.<br>”);
}
window.y();

</script>
</head>
<body>

</body>
</html>

Output:-

Global function invoked using window object.

 

 If you want to window object  print  with alert pop up, then you have simple code, let’s begin with help of an example of programming.

For Example:-

<!DOCTYPE html>
<html>
<head>
<script>

alert(“alert invoked invoked using window object.”);
window.alert(“alert invoked using window object.”);

</script>
</head>
<body>

</body>
</html>

Output:-

after click OK then show next alert.

 

If you want to see your browser width & height in the help of window object, then you have a simple code, let’s begin with help of an example of programming.

For Example:-

<!DOCTYPE html>
<html>
<head>
<script>

//width of browser window
document.write(“window width:” + window.innerWidth +”in pixels <br>”);

//height of browser window
document.write(“window height:” + window.innerHeight +”in pixels <br>”);

</script>
</head>
<body>

</body>
</html>

Output:-

window width:1024 in pixels

window height:728 in pixels

In the syntax you have a three condition hide in the comment line whenever you want execute any function you can UN-hide this function and run on the browser. first set window name and print your browser, second close window, with help of this you can close your browser window, third is open new window help of this function you can open new window with your given website address with a variety of size, then you have a simple code, let’s begin with help of an example of programming.

For Example:-

<!DOCTYPE html>
<html>
<head>
<script>

//set window name
window.name = “Rohit’s window”;
document.write(“window name:” + window.name +”<br>”);

//close window
//window.close();

//open new window
//window.open(“https://www.staracademytech.com”, “Star //academy window”, “width=150,height=150”);

</script>
</head>
<body>

</body>
</html>

Output:- 1. code output:-

window name: Rohit’s window

2. code output:-

automatic close your browser.

3. code output:-

open new browser and open your website.

 

Learn j-query & Ajax :-

What is j-query  & Ajax?

Ajax :- “Ajax means Asynchronous JavaScript and XML.  It is Allows you to load data in the background and display it on your web-page, without refreshing the page. This is allow very small functionality to creating website.”

For example:- You have the very good example in your surrounding like- Facebook, Gmail, YouTube, Google Map etc.

Jquery :-” jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers. With a combination of versatility and extensibility, jquery has changed the way that millions of people write JavaScript.” 

jquery and Ajay both are important each other. Let’s start the programming about jquery and ajax :-

Php Examples with Source code and output

For example :-(1.) 

<!DOCTYPE html>
<html>
<head>
<script>

src=”https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js”></script>
<script>
$(document).ready(function(){
$(“button“).click(function(){
$(“#div1“).load(“printpg.txt #p1”);
});
});
</script>
</head>
<body>

<div id=”div1″><h3>Hello ! Welcome to our query example.</h3></div>

<button>click Ok</button>

</body>
</html>

Output:-

After clicking this click OK button you will be displayed blow text :-

For Example:-(2.)

<!DOCTYPE html>
<html>
<head>
<script>

 src=”https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js”></script>
<script>
$(document).ready(function(){
$(“#hide“).click(function(){
$(“h2“).hide();
});
$(“#show“).click(function(){
$(“h2“).show();
});
});
</script>
</head>
<body>

<h2>If you click on the “Hide” button, I will disappear.</h2>

<button id=”hide”>Don’t show message</button>
<button id=”show”>Show my message</button>

</body>
</html>

Output:-

If you click on the “Hide” button, I will disappear.

Don’t show message

 

Show my message

In this programming, you have to see an output of the result, in this output, have to show two button

(1)Don’t show message     (2) Show my message

If you will click on Don’t show button then your text is hidden otherwise you can click on Show my message then show your hide text. when you apply this Php Examples with Source code and output

 

For Example:-(3.) (Php Examples with Source code and output)

<!DOCTYPE html>
<html>
<head>
<script>

src=”https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js”></script>
<script>
$(document).ready(function(){
$(“button“).click(function(){
$(“h2“).hide(2400);
});
});
</script>
</head>
<body>

<h2>This hiding option with timing.</h2>

</body>
</html>

Output:-

Don’t show me message

This hiding option with timing.

In this example, you will see the hiding text with slowly-slowly with timing. after few second your text automatically hides and show only one button in the browser.

 

For Example:-(3.)

<!DOCTYPE html>
<html>
<head>
<script>

src=”https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js”></script>
<script>
$(document).ready(function(){
$(“button“).click(function(){
$(“#mypart1“).fadeIn(“slow“);
$(“#mypart2“).fadeIn(“slow“);
$(“#mypart3“).fadeIn(25000);
});
});
</script>
</head>
<body>

<p>Click on the button</p>

<button>Click Me</button><br>

<div id=”mypart1style=display:none;width:80px;height:80px;background-color:green;border:2px solid blue””></div><br>
<div id=”mypart2style=”display:none;width:80px;height:80px;background-color:yellow;border:2px solid blue”></div><br>
<div id=”mypart3style=”display:none;width:80px;height:80px;background-color:red;border:2px solid blue”></div>

</body>
</html>

Output:-

In this coding, you will learn about how can fadeIn the colour boxes with the help of programming. 

 

 

1 thought on “Php Examples with Source code and output

  • Not only wind and not only in Australia. Here is some data from Brooks Solar Farm in Alberta. Here is the May summary and YTD for Brooks Solar. Brooks Solar May output summary 11,160 MWh total capacity 3039 MWh actual output 27.20% of capacity in May 744 hour total in May 506 hours with power 238 hours with zero power 32% with zero power 386 hours at 52% hours at Brooks Solar January 1 to May 31 output summary JANUARY THRU MAY 120 days 2880 HOURS TOTAL TIME 54,360 MWh potential 9607 MWh produced 17.7% of capacity YTD 1864 Hours with power 1760 hours with zero power 48.6% of hours with zero power 2425 Hours at less than 10% of capacity 67% Hours at less than 10% of capacity May output was higher then my January estimate, but below my updated estimate done in April. My updated estimate for the year is 19.7% output.

Leave a Reply

Your email address will not be published. Required fields are marked *