php
features
simpler to learn and easier to implement (good news to learner)
it can work faster
highly flexible ( changes can be done without developers intevention)
platform indepedent( any platform can work)
interpreted ( does not need to be compiled)
open source
dynamic webpages
securiety encryption
cost effiecient
work with so many databases
it can run on any enviroment
it is old languagte and it has large community support
80 % web is stilll powered by php
wordpress
shopify
opencart
magento, joomla, drupal, wix, square space
presta shop
laravel
codeignitor
zend framweork
symfony
cakephp
yii framwework
https://youtu.be/6EukZDFE_Zg
php stands for
hyper text pre processor
it is an opensource serer side scripting language
that is embeded into htm and used for webdevelopments
syntax
<?php ?>
<?php
echo "hellow wold";
?>
how does php work
BROWSER REQUEST TO SERVER
PHP INTERPERETER
based on the request, it proceess , it pulls data from databse
developed in php
wordpress,tumblr,yahoo
facebook,wikipedia
we can xampp
cross platform , apache sereer, mariad db, php, perl
sring
array =
$laptop =array("hp","lenovo","asus");
comments, multi line comments
var_dump
print_R
echo
concatenate string and varaible,
define strings , array => declaring constatns
at anny case programm value cannot modify
at any ase value cannot
if we declare declare(strict_types=1);
define("laptops",["hp","lenovo"]);
echo laptops[2];
task print varaibvle if it si greater than 7
$var = 8;
if($var > 7){
echo $var;
}
else {
}
else is used if condition is not matched
&& and conditon
|| or conditon
($var % 3 ==0)
elseif
switch() or match
default
break
case
php loops
for loop
for loop
while loop
as long as conditon true,it loops
while(condition){
executes}
while do (ist excutes then lopo)
do{
executes}
while(conditon){
lop executes}
for(inistialisation,condtion, incrimentafterloop)
ist $is=0,
then condtion check
then go to inside
then postincriment
then condtion
then loo
\
inbuilt functions
echo (var,string,object,array)
function user defined
some time some code is repeating, we will call this function where ever require
if we dont call, length of code increases
oops conspts in php
class
object
constructor
destructior
inheritance
polymorphism
public
private
protected
instance
static => ::
class fruit {
public $name;
public $color;
function set_name($name){
$this->name=$name;
}
function get_name(){
$this->name;
}
}
$apple =new fruit(); it is object or instance
car is class
bmw is object
objectsa re calusing new
bmw is properites
every objects has properties and functoins
member vraibles
member functions
function __construct(){
}
function __destruct(){
private upto that class
protected upto child but can acess from public function
inherited or derived or extends ( inherited calsas can access all properties and functons of parent class)
echo "s {$this->name}
polymorphism( same function in parent and child and if we call child class, it executes child functions only if have same funciton name, ist child then parent )
vs code extensions
php intellipehnce
giving suggestioins for the params
php mess detector
error detecting analys code
auto close tag
it will call close end tag automaticlyy
phpfmt php formaterr
clean indentation
php debug
to debug errors
xdebug .org
get and post in php
get is encode user information with question mark in url
it si restriction if sending up to 1024 cjaracters
dont share confidential infromation using get
in server logs=>it builds a long string
get cannot besued to share images or word cdocumetn to the server
data sent by get method can be accesses using query_string environment varaible
<?pohp
if isset($_GET['NAME]) || isset($_GET{'AGE']){
exit();
$_PHP_SELF => SAME URL
POST METHOD
its sends via http headers
no restriction on datasize to be sent
it sends ascii as well as images and documents
security
if(isset($_+POST{'NAME]) || isset($_post['age'){
$_request['name')
$_SERVER['REQUEST_METHOD']=='POST'
post is
php development career road map
udemy, youtube
any development career is good starts is good
php is using start up companies ( after 2 year realtime experience )
html ,css,js it is plus
databse is plus
php with my sql
https://www.computerhope.com/htmcolor.htm
<body bgcolor="colorcode">
</body>
php form validations
IF(empty($_post['name']
test_input($_post['name];
stripslashes
htmlspecialchars
database file
if isset $_post['submit']
create
selectif($resilt->num_rows>0
while ($row= $result->fetch_Assoc(){
update
database
session_Start();
session_unset();
session_Destroy();
header{'location:index.php);
rest api
cient to server
stateless
cacheable
uniform interface
layered sstem
code on demand
it uses http method (crud)
mysqli_Select_Db($con,$photography)
my_Variable
variable starts with undescore or leter
$My__Varaible
popular phgp frameword
isset()
definaed varaible that has value or not
objects in pph
new fruit();
display outpyt in browser
<?= ?>
define declared cosntatnt
$vairalbge
simple variable
$$varaible => variabel of variables
fianl class s
its class cannot extended
it cannot be ovverridden
over loading
same function repeated in same calss
overl riding
same function in parent and child clas
php accepts riding not overloading
== and ===
type and value
how does exception handling work in phprequire and include
require -==> file not found throw error, stops execution
include => file not found, produce warning, execute remaingn script
types of error
notice
warning
fatal
how to call a function by referecnce
single ton clas in php
that have only one object
encrypt a password using phpsort,rsort,asort,ksort,arsort,krsortwhat is the output of following cocde
php and javascript interact
explain typehinting is php
if datatype is not matched , it wills how error
wrte a class to solve the following question
https://www.youtube.com/watch?time_continue=22941&v=6EukZDFE_Zg&embeds_referring_euri=https%3A%2F%2Flearntube.ai%2F&embeds_referring_origin=https%3A%2F%2Flearntube.ai&source_ve_path=MTI3Mjk5LDEyNzI5OSwyODY2MywzNjg0MiwyODY2Ng&feature=emb_logo
php syntax
<?php
echo "h";
?>
php varaibles
modify varibble data type by storing resepective data
const pi =3.14
php echo /print
echo "html;" tags;
print"html tags";
both are same
tasks
Question
In this task, you have to create a variable following the proper PHP syntax and give it the value “Learning PHP from LearnTube”. Print the variable created in the output.
Description
Step 1: To work on the given task you can do it from the xampp server in your local machine or try any online php compiler.
Step 2: Write the code for the given program and run it.
Program:
<?php
$txt = "Learning PHP from LearnTube";
echo $txt;
?>
Step 3: Share your code in a google doc and a screenshot of the final result in PNG format by clicking on the "Upload Here" Button.
==
php strings
difference between double quoites and signle quoites
'single quote'
'single \' quote'
"double {} quotes"
In PHP, there are two primary ways to specify string literals: using double quotes (" "
) and single quotes (' '
). Here are the key differences between them:
Variable Parsing:
- Double quotes allow variable parsing, meaning that variables and escape sequences inside the string are interpreted and replaced with their values. For example:php
$name = "John"; echo "Hello, $name!"; // Outputs: Hello, John!
- Single quotes do not perform variable parsing. They treat everything inside them as a literal string, including variables and escape sequences. For example:php
$name = "John"; echo 'Hello, $name!'; // Outputs: Hello, $name!
- Double quotes allow variable parsing, meaning that variables and escape sequences inside the string are interpreted and replaced with their values. For example:
Escape Sequences:
- Both double quotes and single quotes support escape sequences, such as
\n
for newline,\t
for tab,\"
for double quote,\\
for backslash, etc. - However, when using double quotes, escape sequences are interpreted and replaced with their actual characters. In single quotes, escape sequences are treated literally.php
echo "Hello\nWorld"; // Outputs: // Hello // World echo 'Hello\nWorld'; // Outputs: Hello\nWorld
- Both double quotes and single quotes support escape sequences, such as
Performance:
- Single quotes are slightly faster than double quotes because they don't involve variable parsing or interpreting escape sequences.
- However, the performance difference is often negligible in most PHP applications unless you're dealing with a massive number of string operations.
Use Case:
- Double quotes are commonly used when you need to include variables or escape sequences within the string.
- Single quotes are useful for string literals that don't require variable interpolation or where you want to ensure that special characters are treated literally.
inteface example
php numbers
https://www.youtube.com/watch?v=2eebptXfEvw&t=1571s
php super globals
$GLOBALS
$_POST
$_GET
$_COOKIE
$_SESSION
DIFFERENCE BETWEEN COOKIE AND SESSION
Sessions and cookies are both mechanisms used in web development to store information and maintain state across multiple HTTP requests. However, they differ in several key aspects:
Storage Location:
- Session: Session data is stored on the server. The client (browser) receives a session ID, typically in the form of a cookie, which is used to identify the session data stored on the server.
- Cookie: Cookies are small pieces of data sent from a website and stored in the user's browser. They are primarily used for client-side storage.
Lifetime:
- Session: Session data typically lasts for the duration of a user's visit to a website. When the user closes the browser or the session expires due to inactivity, the session data is usually destroyed.
- Cookie: Cookies can have different lifetimes. They can be session cookies (deleted when the browser is closed) or persistent cookies (stored on the user's device for a specified period or until manually deleted).
Data Storage:
- Session: Sessions can store more data compared to cookies because the data is stored on the server. This makes sessions suitable for storing sensitive or larger amounts of data.
- Cookie: Cookies have size limitations (commonly around 4KB per cookie). They are generally used to store smaller amounts of data, such as user preferences, authentication tokens, or tracking information.
Access:
- Session: Session data is accessible on the server-side. In PHP, for example, session data can be accessed using
$_SESSION
superglobal. - Cookie: Cookies are accessible on the client-side (browser). JavaScript and server-side scripting languages like PHP can access cookies, but the data is stored on the client's browser.
- Session: Session data is accessible on the server-side. In PHP, for example, session data can be accessed using
Security:
- Session: Session data is typically more secure than cookies because it is stored on the server. However, sessions are still vulnerable to session hijacking or fixation attacks if not implemented securely.
- Cookie: Cookies can pose security risks, such as cross-site scripting (XSS) and cross-site request forgery (CSRF), if not used and managed properly. Secure and HTTP-only flags can be set to enhance cookie security.
In summary, sessions are more secure and suitable for storing sensitive or larger amounts of data on the server-side, while cookies are commonly used for smaller data storage and client-side operations like maintaining user preferences and tracking user activity. The choice between sessions and cookies depends on the specific requirements and security considerations of the web application.
===
REGESX
PREG_MATCH
PREG_REPLACE
REQUIRE_ONCE
RUN PHP IN TERMINAL php
inteface
transversable
=
top 10reasons to learn php
so many websites using php
its easy to learn
opn source
frameworks (its easy to build large applicaton)
cross platform ( linux, mac, windows)
multi databse (mysql ..)
php sacalabilty ( if u wann change to large scale)
community ( biggest community)
check last update
job market
why php is still so important for webdevelopment
accoirding to survey report form w3techs.com
10 million plus website using php
No comments:
Post a Comment