Php Code – Codemeets– 02
by sanka · Published · Updated
PHP Code Lesson 2: Expanding Your PHP Knowledge
Welcome to php code Lesson 2 of our PHP tutorial! Today, we will explore essential PHP concepts, including HTML integration, Variables, Strings, Numbers, and Operations. By the end of this lesson, you’ll gain a deeper understanding of how PHP works in web development.
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 in PHP
A string is a sequence of characters enclosed in single (”) or double (“”) quotes. PHP provides various built-in functions to manipulate and work with strings efficiently.
<?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 in PHP
Numbers are fundamental in every programming language, and PHP provides various functions to handle and manipulate them. PHP supports both integers (whole numbers) and floating-point numbers (decimals).
<?php
echo 5; //5
echo 5 + 9; //14
?>
<?php
$num = 10;
$num ++;
echo $num; //11
Mathematical Operations in PHP
Mathematics involves a variety of operations such as finding maximum values, square roots, and flooring numbers. PHP provides several built-in functions to perform these operations efficiently. Let’s dive deeper into these mathematical operations.
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!