Java Techies- Solution for All
PHP Examples
First Simple Example.
How to use Comments in PHP.
How to work Constant in PHP.
How to print the Output.
How to use variables in PHP
How to make Function in PHP
How to make Array in PHP
How to write String in PHP
How to design Forms in PHP
File Upload in PHP

How to use filter in PHP
How to create session in PHP
First Program
First.php
<!DOCTYPE html> <html> <body> <?php echo "First PHP Program"; ?> </body> </html>
Output :
First PHP Program
How to use Comments in PHP.
Comments
comment.php
<!DOCTYPE html> <html> <body> <?php //This is a PHP comment line /* PHP comment block */ ?> </body> </html>
How to work Constant in PHP.
Constant
constant.php
<!DOCTYPE html> <html> <body> <?php define("Greeting","hiiii it is jtechies Heights"); echo constant("Greeting"); ?> </body> </html>
Output :
hiiii it is jtechies Heights
How to print the Output.
Output
Output.php
<!DOCTYPE html> <html> <body> <?php echo "jtechies!"; ?> </body> </html>
Output :
jtechies!
How to use variables in PHP
Variable
variable.php
<!DOCTYPE html> <html> <body> <?php $x=3; $y=3; $z=$x+$y; echo $z; ?> </body> </html>
Output :
6
How to make Function in PHP
Function
Function.php
<?php function writeName($fname) { echo $fname . " Hi.
"; } echo "My name is "; writeName("Siddle"); echo "My sister's name is "; writeName("Lita"); echo "My brother's name is "; writeName("Peter"); ?>
Output :
My name is Siddle Hi. My sister's name is Lita Hi. My brother's name is Peter Hi.
How to make Array in PHP
Array
Array.php
<!DOCTYPE html> <html> <body> <?php $numbers=array(2,34,35,89,90); rsort($numbers); $arrlength=count($numbers); for($x=0;$x<$arrlength;$x++) { echo $numbers[$x]; echo "
"; } ?> </body> </html>
Output :
90 89 35 34 2
How to write String in PHP
String
String.php
<!DOCTYPE html> <html> <body> <?php $first= "jtechies is a free tutorial website."; print($first); $second = str_replace("jtechies", "jtechies Heights",$first); print($second); ?> </body> </html>
Output :
jtechies is a free tutorial website. jtechies Heights is a free tutorial website.
How to design Forms in PHP
Form
Form.java
<!DOCTYPE html> <html> <body> <form action="test.php" method="get"> Name: <input type="text" name="name"> City: <input type="text" name="city"> <input type="submit"> </form> </body> </html>
Output :

File Upload in PHP
File Upload
upload_design.php
<html> <body> <form action="upload_file.php" method="post" enctype="multipart/form-data"> <label for="file">Upload:</label> <input type="file" name="file" id="file"><br> <input type="submit" name="submit" value="Submit"> </form> </body> </html>
upload_file.php
<?php $allowExts = array("gif", "jpeg", "jpg", "png"); $tempf = explode(".", $_FILES["file"]["name"]); $ext = end($tempf); if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/pjpeg") || ($_FILES["file"]["type"] == "image/x-png") || ($_FILES["file"]["type"] == "image/png")) && ($_FILES["file"]["size"] < 20000) && in_array($ext, $allowExts)) { if ($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br>"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br>"; echo "Type: " . $_FILES["file"]["type"] . "<br>"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>"; echo "Stored in: " . $_FILES["file"]["tmp_name"]; } } else { echo "Invalid file"; } ?>
Output :

Upload: Form.png Type: image/x-png Size: 4.0322265625 kB Temp file: C:\xampp\tmp\phpF4C1.tmp
How to use filter in PHP
Filter
filter.php
<?php $int= 10000000123; if(!filter_var($int, FILTER_VALIDATE_INT)) { echo("Integer is not valid"); } else { echo("Integer is valid"); } ?>
Output :
Integer is not valid
How to create session in PHP
Session
session.php
<?php session_start(); // store session data $_SESSION['count']=15; ?> <html> <body> <?php //retrieve session data echo "Pageviews=". $_SESSION['count']; ?> </body> </html>
Output :
Pageviews=15