Php Code – Codemeets– 02
by sanka · Published · Updated
php code lesson 2. Today we going to learn more about php. In this tutorial, we will focus on HTML, Variable, Strings, Numbers, and Operations. It can provide extensive knowledge.
Use HTML For PHP
You can see below html tag use in your php file.
<?php
echo "<h1>Micke</h1>";
echo "<hr>";
echo "<h1>Jhone</h1>"
?>
Use Variable
Variables are used to store information to be referenced and manipulated in a computer program. They also provide a way of labeling data with a descriptive name, so our programs can be understood more clearly by the reader and ourselves. It is helpful to think of variables as containers that hold information. Their sole purpose is to label and store data in memory. This data can then be used throughout your program.launchschool.com
Now you know what is variable, let’s use it php code.
<?php
$charname ="Jhone";
$charage = '18';
echo "my name is = $charname";
echo "<br>";
echo "my age = $charage";
?>
Working with Strings
string is traditionally a sequence of characters. now you can see how to work it. Look at Example.
<?php
$pharase = "Hello World";
Code | Output |
echo strtoupper ($pharase); |
HELLO WORLD |
echo strtolower ($pharase ); |
hello world |
echo strlen ($pharase ); |
10 |
echo pharase [1]; |
e |
echo str_replace("Hello","Hay",$pharase); |
Hay World |
echo substr ($pharase ,6); |
ld |
echo substr ($pharase ,4,7); |
owor |
Syntax
Working With Numbers
Every computer language uses numbers in particular. This is because it allows you to easily control the data. let show you how to work with numbers in php.
<?php
echo 5; //5
echo 5 + 9; //14
?>
<?php
$num = 10;
$num ++;
echo $num; //11
Operations
In mathematics we use different operations i.e. maximum value, square root, fall. They are also used differently in programming. The following example will give you a broader understanding.
Name | Syntax | Output |
Power | echo pow(2,4); |
16 |
Square root | echo sqrt(144); |
12 |
Max Number | echo max(10,20,30); |
30 |
Min Number | echo min (10,20,30); |
10 |
Round | echo round (3.2); |
3 |
NOT | echo abs(-100); |
100 |
Max Round | echo ceil(3.2); |
4 |
Min Round | echo floor(3.8); |
3 |
Operations
Special Example for Lesson 02
Q1
-
- First get square root in x.
-
- y is max round number.
-
- z is positive number.
-
- R is X+Z/Y.
-
- (X=144, Y=2.2, Z=-33)
-
- Find R?
<?php
$x = 144;
$y = 2.2;
$z = -33;
$x1 = sqrt($x);
$y1 = ceil($y);
$z1 = abs($z);
$R1 = $x1 + $z1;
$R = $R1 / $y1;
echo "R";
?>
<?php
$x = 144;
$y = 2.2;
$z = -33;
$x1 = sqrt($x);
$y1 = ceil($y);
$z1 = abs($z);
$R1 = $x1 + $z1;
$R = $R1 / $y1;
echo "R = ";
echo $R;
?>
Thank for all!
More php ClickHere!
See you Next php Lesson Soon!