Simple scripts in php for beginnersPrinting Hello World
<?Php echo "Hello World"; ?> Printing Pattern of * using for loop
<?Php for($i=0;$i<20;$i++){ for($j=0;$j<$i;$j++){ echo '*'; } echo '<br>'; } ?> Demo Printing welcome message and reversing the user entered string
<?Php echo "<form name=f1 method=post action=''> <input type=text name=t1><input type=submit value='Submit'></form>"; @$t1=$_POST['t1']; // Collect the string as entered by user if(strlen($t1) > 1 ){ // If the length of the string is more than 1 echo "Welcome $t1<br> Your name in reverse : ".strrev($t1); } ?> Demo Length of a string in PHP
<?Php
Demo$string= "Welcome to plus2net.com"; echo $string."<br>"; echo "Length of the string : ".strlen($string); ?> Changing first character of the string to uppercase
<?Php
Demo$string= "Welcome to plus2net.com"; echo $string."<br>"; echo "Length of the string : ".strlen($string); ?> Multiplication table of a number
<?Php
Demo$v1=5;// Change this number for($i=1;$i<11;$i++){ echo "$v1 x $i = ".$v1*$i; echo '<br>'; } ?> Sum of two numbers
<?Php
Demo$v1=10; $v2=30; echo "Sum of two numbers $v1 + $v2 = ". ($v1 + $v2); ?> Displaying Even Numbers
<?Php
Demofor($i=1;$i<=20;$i++){ if($i % 2 ==0){ echo $i; echo '<br>'; // Line break } } ?> Highest of four Numbers
<?Php
Demo$v1=68; $v2=12;$v3=135;$v4=22; echo "Four Numbers are : $v1,$v2,$v3,$v4 <br>"; echo " Highest Number is : ".max($v1,$v2,$v3,$v4); ?> Print todays Date and time
<?Php
Demoecho date("m/d/y : H:i:s", time()); ?> Displaying last 20 days calendar details
<?Php
Demo$m= date("m"); $de= date("d"); $y= date("Y"); for($i=0; $i<=20; $i++){ echo date('d-M-Y:D',mktime(0,0,0,$m,($de-$i),$y)); echo "<br>"; } ?>
This article is written by plus2net.com team.
![]() | ||||||||
| ||||||||