   PHP.   
 


 !  !        PHP.       ,          PHP-,     .             .     !   ,    !





   PHP

  



 



 ,2022



ISBN978-5-0059-3322-5

     Ridero




   ?


        PHP-. PHP     -.      ,      .      PHP.

    -,   .

    -  ,                 .




   ?


      .        ,         .             .

    ,      ,      .

       PHP,     .

     ,    PHP-     ,    .     .






. 1.     PHP-.



     PHP    :http://learn-coding.today/gd/php_img.zip




 ,   


  PHP   PHP notepad++.    .

  -.   Chrome  Firefox.  Google  Google Chrome  Windows 1064-,   .

   PHP : https://www.php.net/downloads.php.

. .2.






 2. PHP.



    Windows,   Windows -  PHP...3.






 3. PHP.



   Thread Safe   Zip.   php       PHP  .    C:/php...4






 4.  PHP C




  


       .  ,     ..5.






. 5.   .



         .    . .  67.






 6.  



. 7.   .

           . . .8.






 8.   .



        .     .       php (C:\php)  .

. .9.






 9.  PHP   



  ʻ  PHP.

  ,      php-,   phpprojects.   phpprojects   images.  images      ,   PHP.




PHP


        CMD.     . . .10.






. 10.    .



   .     C:\Users\Owner>.

    phpprojects.

 cd..  Enter.    .

C:\Users\Owner>cd..

C:\Users>

 cd..  Enter.

   C:\.

 cd phpprojects  Enter.    phpprojects.

      PHP.

php -S localhost:8000

 Enter.






 11. PHP



PHP . .  1112.  11.   phpprojects PHP.






 12. PHP- .



      PHP-.

 notepad ++ :

<?php

echo Computer programming is Fun!;

?>



   index.php.

 ,  URL-: http://localhost:8000   . -   堖  ! .

      ,    ,      .

 ,    .   堖   ,    .  蠖   ,    .

,     X = 5, X  .    X = 5

 ,      5.




 


,     ,    .      ,  integer,    ,  float  double. , 7 integer, 7,5   , float.

            ,     . ,   7276781209  ,     .

  Boolean  true  false.    . ,

$ = true;  $= false;

   $x = true,  $x   ,  .

  Null   null,   . , $x = null;

    ,  .    .







 PHP          . . $date $Date    .  : $x =5;



		$street_address=1090Oak Street;
		
		$street_address=1090Oak Street;

   ()      .

  echo     -  .

 PHP     '<?php ?>.

  PHP     .

//'    .

		: address.php
		<?php
		$street_address=1090Oak Street;
		$city = Brooklyn;
		state=NY;
		$zip=11276;
		$address=$street.,. $city.,. $state.,. $zip;
		echo $address;
		?>
		Output: 1090Oak Street, Brooklyn, NY, 11276

       -.

		: declare.php
		<?php
		//   
		$a=7;
		$b =4;
		//   
		echo int a=. $a. "<br>;
		echo int b =. $b. "<br> <br>;
		?>
		Output:
		int a=7
		int b =4

    .

  PHP- arithmetics.php.

		<?php
		$a=7;
		$b =4;
		//   
		echo int a=. $a. "<br>;
		echo int b =. $b. "<br> <br>;
		//  
		$sum = $a+ $b; //
		$subtraction=$a $b; //
		$product=$a* $b; //
		$division=$b / $a; //
		$modulo=$a% $b; //  
		//  
		echo  = a+ b <br>;
		echo  =. $sum. "<br>;
		echo  = b a<br>;
		echo  =. $subtraction. "<br>;
		echo  <br>  = a* b <br>;
		echo  =. $product. <br>;
		echo "<br>  = b / a<br>;
		echo  =. $division. "<br>;
		echo  =".round ($division,2). "<br>;
		echo "<br>   = a% b <br>;
		echo modulo =. $modulo. "<br> <br>;
		?>

 arithmetics.php  .

		int a=4
		int b=7
		 = a+b
		 =11
		 = a*b
		 =28
		 = a/b
		 = 0.57142857142857
		 =0.57
		  = a%b
		modulo =4

 round  ,    .

         2,   0,57.   :

		round ($division,4),

  0,5714.

   . ,

		10% 3= 1,   3* 3= 910 9=1.

   7% 4= 3,   4* 1= 47 4=3.

    .  ,       ,   ?

		: string_arithmetics.php
		<?php
		$c =6;
		$d =5;
		echo str c =. $c. "<br> <br>;
		echo str d =. $d. <br> <br>;
		echo sum = c + d; (  ) <br> <br>;
		//    
		$sum=$c +$d
		echo sum=. $sum. <br> <br>;
		?>
		The outputis:
		str c=6
		str d=5
		sum = c + d; (  )
		sum=11

PHP    . 6+5= 11.       .   concatenate.php.

		<?php
		$a=7;
		$b =4;
		$c =6;
		$d =5;
		echo int a=. $a. "<br> <br>;
		echo int b =. $b. "<br> <br>;
		echo str c =. $c. "<br> <br>;
		echo str d =. $d. "<br> <br>;
		echo    <br> <br>;
		$str1=$a.$d;
		echo srt1=. $str1. <br>";//output str=45
		echo      <br>;
		$str2=$a.$b;
		echo srt2=. $str2; // output str=47
		?>
		Output:
		int a=7
		int b=4
		str c=6
		str d=5
		  
		srt1=75
		    
		srt2=74

PHP        .    PHP     .







      .       .










   .     .         .

    .     0.     1 .

     :

		$container = array();

    .     .

		$fruit = array (Apple, Plum, Orange, Banana, Mango, Lemon, Pear);

      ,    ().

echo $fruit [0]; // output Apple

echo $fruit [1]; // output Orange

echo $fruit [2]; // output Banana



       .      HTML.  HTML   .      ,  堖 ,  堖 .

, #FF0000   , #00FF00   , #0000FF   .

$colors = array (red => #FF0000, orange => #FFA500, yellow=> #FFFF00, green => #008000);

echo $colors [orange]; // output #FFA500

echo $colors [yellow]; // output #FFFF00

echo $colors [green]; // output #008000




If-else 


 if-else    .

,   ,   .      .

        :



if ($weather == raining)

$plan= we stay at home;

else

$plan= we go tothe beach;



 if-else    :



if ($weather==Hurricane)

$plan= we go toashelter;

elseif ($weather == raining)

$plan= we stay at home;

elseif ($weather==Cloudy)

$plan= we go shopping;

else

$plan= we go tothe beach;



    . ||   .

if (($grade==A) || ($grade==B) || ($grade==C))

$test_result = passed;

else

$test_result = failed;



     ,   ,     .

 && .



if (($weather==sunny) && ($season==summer))

$plan= we go tothe beach;

elseif (($weather==sunny) && ($season==winter))

$plan= we go skiing;



  Ȼ   ,   ,    .

     ().

 ,                 .

         ">,  " <,    "> =,    " <= "  !=.








  ? ,     ,     .

  : ,  !.

  .

  : ,  !.

  .

Ƞ     ,    .

     .




While


		While ($kids!= go tosleep)
		{
		$say= Lets go tosleep;
		}

   while . $a++    $.   

		$a= $a+1;

		: while_loop.php
		<?p
		$a=0;
		while ($a<5)
		{
		$a++;
		echo a=.$a;
		echo,;
		}
		?>
		Output: a=1, a=2, a=3, a=4, a=5,

  $a   1   ,  $a 5.   .    while    ,    .          .




Do While


  while   .   ,  .   Do While     .

		do{
		$say= Lets go tosleep;
		} while ($kids!= go tosleep);
		: do_while.php
		<?php
		$b=0;
		do{
		$b++;
		echo b =.$b;
		echo,;
		}
		while ($b<5)
		?>
		output: b =1, b =2, b =3, b =4, b=5,

      while do while,    ,  .

		$a=7;
		while ($a<5)
		{
		$a++;
		echo a=.$a;
		echo,;
		}

  .      ,  while     .

		$b=7;
		do{
		$b++;
		echo b =.$b;
		echo,;
		}
		while ($b<5)

     ,  do while  b =8.

   ,  .




For


For    .

		for ($i=0; $i<3; $i++){
		echo I=. $i. "<br>;
		}
		The output:
		I= 0
		I= 1
		I=2

 for    .     ,     .

    count     .

: fruit.php

<?php

$fruit = array (Apple, Plum, Orange, Banana, Mango, Lemon, Pear);

for ($i=0; $i<count ($fruit); $i++){

echo $fruit [$i];

echo,;

}

?>

Output: Apple, Plum, Orange, Banana, Mango, Lemon, Pear,

         .

: return_key.php

<?php

$fruit = array (Apple, Plum, Orange, Banana, Mango, Lemon, Pear);



echo  <br> <br>;

print_r (array_keys ($fruit));

echo  <br> <br>;

print_r (array_keys ($fruit, Orange));

?>

Output:

Array ([0] => 0[1] => 1[2] => 2[3] => 3[4] =>4

[5] => 5[6] => 6) //  

Array ([0] => 2) //    

 print_r  .

: colors_key.php



<?php

$colors=array (red=> #FF0000, orange=>

#FFA500);

		echo  <br> <br>;
		print_r (array_keys ($colors));
		echo  <br> <br>;
		print_r (array_keys ($colors, #FF0000));
		?>
		Output:
		Array ([0] => red [1] => orange)
		Array ([0] =>red)




 Foreach ( )


  foreach  ,     ,   .    foreach   .

foreach ($fruit as $value){

echo $value;

echo,;

}

Output: Apple, Plum, Orange, Banana, Mango, Lemon, Pear,

   foreach    .     $fruit.      .       .



foreach ($fruit as $anything){

echo $anything;

echo,;

		}
		Output: Apple, Plum, Orange, Banana, Mango, Lemon, Pear,
		foreach ($colors as $color){
		echo $color;
		echo,;
		}
		Output: #FF0000, #FFA500, #FFFF00, #008000,

    foreach   ,  .

		foreach ($colors as $key => $color){
		echo $key;
		echo "=>;
		echo $color;
		echo "<br>;
		Output:
		red=> #FF0000
		orange=> #FFA500
		yellow=> #FFFF00
		green=> #008000

  ,       ,  $key $color, .

      .     .

		foreach ($colors as $x => $y){
		echo$x;
		echo "=>;
		echo$y;
		echo "<br>;
		Output:
		red=> #FF0000
		orange=> #FFA500
		yellow=> #FFFF00
		green=> #008000








       .        ,   ,     .   .   - ,   - . PHP     .

     頖 ,  .        .    .   ,    .

		function convert_lb_to_kg ($lb){
		$kg = $lb * 0.454;
		return$kg;
		}

    

		function calculate_speed ($miles, $hours){
		$msg=;
		If ($hours==0)
		$msg= "      !;
		else
		{
		$speed = $miles/$hours;
		$msg= . $speed.  .;
		}
		return $msg;

}




    


 ,   ,   .

    &  ,    .

<?php

function convert_lb_to_kg (&$w){

$w= $w* 0.454;

}



$a=100;

convert_lb_to_kg ($a);

echo  100lb =. $a. kg <br>;

?>

Output: 100lb = 45.4kg

    &,      ,   ,   .

		<?php

		function convert_lb_to_kg ($w){

		$w= $w* 0.454;

		}
		$a=100;

		convert_lb_to_kg ($a);

		echo  100lb =. $a. kg <br>;
		?>

		Output: 100lb = 100kg




  


       .

  .    ,   (x)  ,   (y)  .   ,     X Y  .        .        X=0Y=0.

    200 ,    ,   X=200Y=0.

    300 ,    X = 200Y =300.

     X = 800Y = 600   ...13.






. 13. .



     -  PHP-.

      php.ini PHP.   php.ininotepad++   ;extension=gd.     extension=gd, extension=fileinfo extension=gmp.

 .

;extension=bz2

;extension=curl

;extension=ffi

;extension=ftp

extension=fileinfo

extension=gd

;extension=gettext

extension=gmp

;extension=intl

 error reporting,     E_ALL     E_ALL  .






. 14. rror reporting



    ,    PHP.

https://youtu.be/LVEhccXXnOo"




  


      ,      ,    PHP imagecreatetruecolor.     :   .

       imagecolorallocate.    ,   imagecreatetruecolor,   RGB. RGB   (Red),  (Green)  (Blue).

 RGB     0255. , RGB (255, 0, 0) ,

RGB (255, 255, 0) , RGB (0, 255, 0) , RGB (0, 0, 255) .

    RGB   -: https://www.w3schools.com/colors/colors_converter.asp.

      .   ,     imageline,    : ,   imagecreatetruecolor,  X Y   ,   imagecolorallocate.

   -,    :

header (Content-type: image/jpeg);

imagejpeg ($img);    .

 imagedestroy    .

: draw_line.php. (. .15.)

		<?php
		//   
		$img=imagecreatetruecolor (900, 700);
		//  ( )
		$yellow = imagecolorallocate ($img, 255, 255,0);
		// draw aline
		imageline(
		$img, //GdImage
		200, //x1,
		300, //y1,
		800, //x2,
		600, //y2,
		$yellow //color
		);
		header (Content-type: image/jpeg);
		// 
		imagejpeg ($img);
		imagedestroy ($img);
		?>






 15.  . Draw line.



    ,    .  imagesetthickness     .

		: draw_thick_line.php (. .16).

		<?php
		//  
		$img=imagecreatetruecolor (900, 700);

		// set the line thickness
		imagesetthickness ($img,7);
		//  ( )
		$yellow = imagecolorallocate ($img, 255, 255,0);
		//  
		imageline(
		$img, //GdImage
		200, //x1,
		300, //y1,
		800, //x2,
		600, //y2,
		$yellow //color

);

header (Content-type: image/jpeg);

// 

imagejpeg ($img);

imagedestroy ($img);

?>






. 16.  .



 , ,    ,  .    imagedashedline   imageline. imagedashedline   ,   . (   )

   .    . . . 16.   ,     imagefilledellipse.     , GD-,  X Y  , ,  . .    yellow_circle1.php.

File: yellow_circle1.php

<?php

$height=2000;

$width=2000;

//   

$img=imagecreatetruecolor ($width, $height);

//  ( )

$yellow = imagecolorallocate ($img, 255, 255,0);

imagefilledellipse ($img, $width/2, $height/2, $width/2, $height/2, $yellow);

//  

imagejpeg($img,'images/yellow_circle1.jpg,100);

header (Content-type: image/jpeg);

// 

imagejpeg ($img);

imagedestroy ($img);

?>



     .   :

$lightblue = imagecolorallocate ($img, 0, 195, 255);

   ,   imagefilledrectangle.     :  GD,  X1 Y1   (  )  X2 Y2   (  ) .   ,     yellow_circle2.php.  .



imagefilledrectangle ($img, 0, 0, $width, $height, $lightblue);

        imagefilledellipse  ,  17.






 17   .



: yellow_circle2.php

<?php

$height=2000;

$width=2000;

//  

$img=imagecreatetruecolor ($width, $height);

//

$lightblue = imagecolorallocate ($img, 0, 195, 255);

$yellow = imagecolorallocate ($img, 255, 255,0);

// 

imagefilledrectangle ($img, 0, 0, $width, $height, $lightblue);

imagefilledellipse ($img, $width/2, $height/2, $width/2, $height/2, $yellow);

//output the image inthefile

imagejpeg($img,'images/yellow_circle2.jpg,100);

header (Content-type: image/jpeg);

// 

imagejpeg ($img);

imagedestroy ($img);

?>



  ,  18.






 18. .



: sun3.php



<?php

$height=3000;

$width=3000;

//  

$img=imagecreatetruecolor ($width, $height);

//

$lightblue = imagecolorallocate ($img, 0, 195, 255);

$yellow = imagecolorallocate ($img, 255, 255,0);




  .


   .

   ,     (https://www.litres.ru/pages/biblio_book/?art=68617058)  .

      Visa, MasterCard, Maestro,    ,   ,     ,  PayPal, WebMoney, ., QIWI ,       .


