From ad29a56859e3da975151ebc4a1a5c02c529e9e20 Mon Sep 17 00:00:00 2001 From: Jose Torres Date: Mon, 19 Dec 2022 16:40:46 +0100 Subject: [PATCH 1/6] first commit --- index.php | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 index.php diff --git a/index.php b/index.php new file mode 100644 index 0000000..2e98cef --- /dev/null +++ b/index.php @@ -0,0 +1,4 @@ + From 1e7dd85b2b131e526b625198e8093aa78f1528e3 Mon Sep 17 00:00:00 2001 From: Jose Torres Date: Tue, 20 Dec 2022 18:39:05 +0100 Subject: [PATCH 2/6] proyect PHP Basic --- README.md | 51 --------------------- arrays.php | 59 +++++++++++++++++++++++++ conditionals.php | 72 ++++++++++++++++++++++++++++++ date.php | 25 +++++++++++ functions.php | 49 +++++++++++++++++++++ index.php | 4 -- iterators.php | 52 ++++++++++++++++++++++ maths.php | 28 ++++++++++++ operators.php | 110 ++++++++++++++++++++++++++++++++++++++++++++++ phpinfo.php | 3 ++ phpinfo/README.md | 52 ++++++++++++++++++++++ phpinfo/index.php | 3 ++ print.php | 25 +++++++++++ strings.php | 49 +++++++++++++++++++++ types.php | 49 +++++++++++++++++++++ 15 files changed, 576 insertions(+), 55 deletions(-) delete mode 100644 README.md create mode 100644 arrays.php create mode 100644 conditionals.php create mode 100644 date.php create mode 100644 functions.php delete mode 100644 index.php create mode 100644 iterators.php create mode 100644 maths.php create mode 100644 operators.php create mode 100644 phpinfo.php create mode 100644 phpinfo/README.md create mode 100644 phpinfo/index.php create mode 100644 print.php create mode 100644 strings.php create mode 100644 types.php diff --git a/README.md b/README.md deleted file mode 100644 index 7c787c3..0000000 --- a/README.md +++ /dev/null @@ -1,51 +0,0 @@ -`#php` `#basics` `#master-in-software-development` - -# PHP Basics - -

- Version -

- -> In this project you will learn the basic notions of the famous PHP language which is so used in the world of web development. -> -> What distinguishes PHP from other languages ​​such as Javascript is that the code is executed on the server, generating HTML and sending it to the client. - -## Index - -- [Requirements](#requirements) -- [Repository](#repository) -- [Technologies used](#technologies-used) -- [Project delivery](#project-delivery) -- [Resources](#resources) - -## Requirements - -- Learn the basics to program in PHP -- Understand what a server-side language is and what it is used for - -## Repository - -First of all you must fork this project into your GitHub account. - -To create a fork on GitHub is as easy as clicking the “fork” button on the repository page. - -Fork on GitHub - -## Technologies used - -\* PHP - -## Project delivery - -To deliver this project you must send a Pull Request as explained in the Students Handbook. Remember that the PR title must be with the format -- Solution: + NAME AND SURNAME or TEAM NAMES AND SURNAMES. -- For example: "Solution: Josep Riera", "Solution: Josep Riera, Toni Suárez, Marta Vázquez" - -## Resources - -- [What can PHP do?](https://www.php.net/manual/es/intro-whatcando.php) -- [Sample guide for README](https://gist.github.com/Villanuevand/6386899f70346d4580c723232524d35a) -- [XAMPP](https://www.apachefriends.org/es/index.html) -- [How to install XAMPP on Windows](https://www.youtube.com/watch?v=h6DEDm7C37A) -- [What is a web server?](https://www.youtube.com/watch?v=Yt1nesKi5Ec) -- [Web server basics](https://www.youtube.com/watch?v=3VqfpVKvlxQ) diff --git a/arrays.php b/arrays.php new file mode 100644 index 0000000..b5ac8f0 --- /dev/null +++ b/arrays.php @@ -0,0 +1,59 @@ + + + + + + + PHP Arrays + + +

Arrays.php

+ Create a simple string array
$string = ["Juan", "Pepe", "Mario"]
'; + $string = ['Juan', 'Pepe', 'Mario']; + echo '
';
+        var_dump($string);
+        echo '
'; + + echo 'Create a simple numbers array
$numbers = [5, 8.1, 258, 35.9]
'; + $numbers = [5, 8.1, 258, 35.9]; + echo '
';
+        var_dump($numbers);
+        echo '
'; + + echo 'Create a nested array
$nested = [[5, 8.1, 258, 35.9],["Juan", "Pepe", "Mario"]]
'; + $nested = [[5, 8.1, 258, 35.9],['Juan', 'Pepe', 'Mario']]; + echo '
';
+        var_dump($nested);
+        echo '
'; + + echo 'Create a nested array
'; + echo ' Array length: ' . count($string) . '
count($string)'; + echo '
';
+        var_dump($string);
+        echo '
'; + + echo 'Combine arrays
$result = array_merge($numbers, $nested)'; + $result = array_merge($numbers, $nested); + echo '
';
+        var_dump($result);
+        echo '
'; + + echo 'Get last position of an array
end($string)
'; + echo ' Last position: ' . end($string) . ''; + echo '
';
+        var_dump($string);
+        echo '
'; + + echo 'Add elements to array
array_push($string, "Carlos", "Julio")
'; + echo ' Added Carlos and Julio'; + array_push($string, 'Carlos', 'Julio'); + echo '
';
+        var_dump($string);
+        echo '
'; + + + + ?> + + \ No newline at end of file diff --git a/conditionals.php b/conditionals.php new file mode 100644 index 0000000..0bde2e4 --- /dev/null +++ b/conditionals.php @@ -0,0 +1,72 @@ + + + + + + + PHP Conditionals + + +

Iterators.php

+ Today is Monday?

'; + if($fecha->format('w') === 1){ + echo "We are on Monday"; + }else{ + echo "Today is not Monday"; + } + + echo '

Are we in October?

'; + if($fecha->format('M') === 'Oct'){ + echo "We are in October"; + }else{ + echo "We are not October"; + } + + echo '

Is the current minute less than 10?

'; + if($fecha->format('i') < 10){ + echo "The current minute is less than 10"; + }else if($fecha->format('i') > 15){ + echo "The current minute is more than 15"; + }else{ + echo "Does not meet any conditions"; + } + + + echo '

What weekday is today?

'; + switch($fecha->format('l')){ + case 'Sunday': + echo "Today is Sunday"; + break; + + case 'Monday': + echo "Today is Monday"; + break; + + case 'Tuesday': + echo "Today is Tuesday"; + break; + + case 'Wenesday': + echo "Today is Wenesday"; + break; + + case 'Thursday': + echo "Today is Thursday"; + break; + + case 'Friday': + echo "Today is Friday"; + break; + + case 'Friday': + echo "Today is Friday"; + break; + + default: "There are no more days of the week"; + } + ?> + + \ No newline at end of file diff --git a/date.php b/date.php new file mode 100644 index 0000000..6ff2a3a --- /dev/null +++ b/date.php @@ -0,0 +1,25 @@ + + + + + + + PHP Date + + +

Date.php

+ Current date Europe/Madrid:

'; + echo '
';
+    var_dump($fecha);
+    echo '

'; + echo '

Current date: '. $fecha->format('Y-m-d') . '

'; + echo '

Current day: ' . $fecha->format('d') . '

'; + echo '

Current month: ' . $fecha->format('m') . '

'; + echo '

Current minuts: '. $fecha->format('00:i') . '

'; + + ?> + + + \ No newline at end of file diff --git a/functions.php b/functions.php new file mode 100644 index 0000000..080c7fd --- /dev/null +++ b/functions.php @@ -0,0 +1,49 @@ + + + + + + + PHP Functions + + +

Functions.php

+ + Function add
'; + function add($num1, $num2){ + return $num1 + $num2; + } + echo add(20, 30) . '
'; + + echo 'Function multiply
'; + function multiply($num1, $num2){ + return $num1 * $num2; + } + echo multiply(20, 30) . '
'; + + echo 'Function division
'; + function division($num1, $num2){ + echo $num1 / $num2; + } + division(50, 30) . '

'; + + echo '

'; + echo 'Function operation
'; + function operation($num1, $operator, $num2){ + if($operator === '+'){ + echo 'Add: ' . $num1 + $num2 . '
'; + }else if($operator === '*'){ + echo 'Multilply: ' . $num1 * $num2 . '
'; + }else if($operator === '/'){ + echo 'Division: ' . $num1 / $num2 . '
'; + }else{ + echo "Error"; + } + } + operation(70, '+' , 20) . '
'; + operation(11, '*' , 4) . '
'; + operation(65, '/' , 20) . '
'; + ?> + + \ No newline at end of file diff --git a/index.php b/index.php deleted file mode 100644 index 2e98cef..0000000 --- a/index.php +++ /dev/null @@ -1,4 +0,0 @@ - diff --git a/iterators.php b/iterators.php new file mode 100644 index 0000000..77d2765 --- /dev/null +++ b/iterators.php @@ -0,0 +1,52 @@ + + + + + + + PHP Iterators + + +

Iterators.php

+ 1- Iterating with the for loop through an array of strings

+ '; + + echo '

2- Iterating with the foreach loop through an array of strings

+ '; + + echo '

3- Iterating with the while loop through an array of numbers

+ '; + while($count < count($numbers)){ + echo '' ; + $count++; + } + echo '
' . $numbers[$count] . '
'; + + echo '

4- Iterating with the do while loop through an array of numbers

+ '; + do { + echo ''; + $num1++; + } while ($num1 <= 10); + echo '
' . $num1 .'
'; + + + + ?> + + + \ No newline at end of file diff --git a/maths.php b/maths.php new file mode 100644 index 0000000..ae634fb --- /dev/null +++ b/maths.php @@ -0,0 +1,28 @@ + + + + + + + PHP Maths + + +

Maths.php

+ $num1 = 95.52
'; + $num1 = 95.52; + echo 'Absolute value: ' . abs($num1) . '
'; + echo 'Rounded down value: ' . floor($num1) . '
'; + echo 'Rounded up value: ' . round($num1) . '

'; + + echo '$numbers = array (0.8, 9.5, 1, 25);
'; + $numbers = array(0.8, 9.5, 1, 25); + echo 'Highest value: ' . max($numbers) . '
'; + echo 'Lowest value: ' . min($numbers) . '

'; + + echo 'Random number from 0 to 40
'; + echo 'Random value: ' . rand(0, 40) . '
'; + + ?> + + \ No newline at end of file diff --git a/operators.php b/operators.php new file mode 100644 index 0000000..b6e2651 --- /dev/null +++ b/operators.php @@ -0,0 +1,110 @@ + + + + + + + PHP Operators + + +

Operators.php

+ operator +

'; + echo '$num1 = 12
$num2 = 4
'; + $sum = $num1 + $num2; + echo $sum . '
'; + echo 'var_dump($num1 + $num2)
'; + var_dump($sum); + echo '
'; + + echo '

operator -

'; + echo '$num1 = 12
$num2 = 4
'; + $rest = $num1 - $num2; + echo $rest . '
'; + echo 'var_dump($num1 - $num2)
'; + var_dump($rest); + echo '
'; + + echo '

operator /

'; + echo '$num1 = 12
$num2 = 4
'; + $div = $num1 / $num2; + echo $div . '
'; + echo 'var_dump($num1 / $num2)
'; + var_dump($div); + echo '
'; + + echo '

operator *

'; + echo '$num1 = 12
$num2 = 4
'; + $mult = $num1 * $num2; + echo $mult . '
'; + echo 'var_dump($num1 * $num2)
'; + var_dump($mult); + echo '
'; + + echo '

operator %

'; + echo '$num1 = 12
$num2 = 4
'; + $res = $num1 % $num2; + echo $res . '
'; + echo 'var_dump($num1 % $num2)
'; + var_dump($res); + echo '
'; + + echo '

operator ==

'; + echo '$num1 = 12
$num2 = 4
'; + echo 'var_dump($num1 == $num2)
'; + var_dump($num1 == $num2); + echo '
'; + + echo '

operator !=

'; + echo '$num1 = 12
$num2 = 4
'; + echo 'var_dump($num1 != $num2)
'; + var_dump($num1 != $num2); + echo '
'; + + echo '

operator <

'; + echo '$num1 = 12
$num2 = 4
'; + echo 'var_dump($num1 < $num2)
'; + var_dump($num1 < $num2); + echo '
'; + + echo '

operator >

'; + echo '$num1 = 12
$num2 = 4
'; + echo 'var_dump($num1 > $num2)
'; + var_dump($num1 > $num2); + echo '
'; + + echo '

operator <=

'; + echo '$num1 = 12
$num2 = 4
'; + echo 'var_dump($num1 <= $num2)
'; + var_dump($num1 <= $num2); + echo '
'; + + echo '

operator >=

'; + echo '$num1 = 12
$num2 = 4
'; + echo 'var_dump($num1 >= $num2)
'; + var_dump($num1 >= $num2); + echo '
'; + + echo '

operator &&

'; + echo '$num1 = 12
$num2 = 4
'; + echo 'var_dump($num1 < 20 && $num2 > 1)
'; + var_dump($num1 < 20 && $num2 > 1); + echo '
'; + + echo '

operator ||

'; + echo '$num1 = 12
$num2 = 4
'; + echo 'var_dump($num1 < 20 || $num2 > 1)
'; + var_dump($num1 < 20 || $num2 > 1); + echo '
'; + + echo '

operator Xor

'; + echo '$num1 = 12
$num2 = 4
'; + echo 'var_dump($num1 ^ $num2)
'; + var_dump($num1 ^ $num2); + + ?> + + \ No newline at end of file diff --git a/phpinfo.php b/phpinfo.php new file mode 100644 index 0000000..bc82da6 --- /dev/null +++ b/phpinfo.php @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/phpinfo/README.md b/phpinfo/README.md new file mode 100644 index 0000000..aa59fd3 --- /dev/null +++ b/phpinfo/README.md @@ -0,0 +1,52 @@ +# Título del Proyecto + +PHP practice with the Assembler school + + +## Comenzando 🚀 + +These instructions will allow you to get a working copy of the project on your premises for development and testing purposes. + + + +### Pre-requisitos 📋 + +XAMPP software installation + + + +### Instalación 🔧 + +- [Guide to install XAMPP](https://www.php.net/manual/es/intro-whatcando.php) + +When you have installed XAMPP follow the steps below. +1 - clone repository. +2 - save the repository in the folder on drive C: > xampp > htdocs. + + + +## Ejecutando las pruebas ⚙️ + +To view the file, type the following in your browser: + +#### localhost/folder-name + + + + +## Construido con 🛠️ + +_Menciona las herramientas que utilizaste para crear tu proyecto_ + +* [PHP](https://www.php.net/) + + + + +## Autores ✒️ + +* **Jose Torres** - *Trabajo Inicial* - [88jose](https://github.com/88jose) +* **Assembler Institute of Tecnology** - [assembler-institute](https://github.com/assembler-institute) + + + diff --git a/phpinfo/index.php b/phpinfo/index.php new file mode 100644 index 0000000..968c8df --- /dev/null +++ b/phpinfo/index.php @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/print.php b/print.php new file mode 100644 index 0000000..4bb980c --- /dev/null +++ b/print.php @@ -0,0 +1,25 @@ + + + + + + + PHP Print and Echo + + +

Print.php

+ Display variables with echo statement: ' . $name . " " .$surname .'

'; + + print '

Display variable with print statement: '. $name .'

'; + echo '
'; + echo '

Show nested array with print_r statement

'; + echo '
';
+        $compra = array ('verdura' => array ('pimiento', 'calabaza', 'berengena'), 'fruta' => array ('pera', 'manzana', 'uvas'));
+        print_r($compra);
+        echo '
'; + ?> + + diff --git a/strings.php b/strings.php new file mode 100644 index 0000000..e21982f --- /dev/null +++ b/strings.php @@ -0,0 +1,49 @@ + + + + + + + PHP Strings + + +

Strings.php

+ Print a text string: "I am a text string"

'; + + $phrase = 'Today is a good day'; + echo 'Print phrase with variables: ' . $phrase . '

'; + + $name = 'Jose'; + $surname = 'Torres'; + echo 'Print sentence with concatenated variables: My name is: ' . $name . ' my surname is: '. $surname .'

'; + + echo 'Replace text
'; + echo 'Hello world! Today is a great day
'; + echo str_replace('world', 'Jose', 'Hello world!') . '

'; + + echo 'Repeat text 10 times:
'; + echo str_repeat('Hi!
', 10); + + echo '
Know the number of characters that the string of the variable has: $phrase = "Today is a good day";
'; + echo strlen($phrase); + + echo '

Position of a word: $phrase = "Today is a good day";
'; + echo strpos($phrase, 'good'); + + echo '

Convert text string to uppercase: $phrase = "Today is a good day";
'; + echo strtoupper($phrase); + + echo '

Convert text string to lowercase: $phrase = "Today is a good day";
'; + echo strtolower($phrase); + + echo '

Get substring of text from array.php file
'; + // primer parametro posicion del array, segundo parametro posicion de la letra y tercer parametro cuantas letras queremos mostrar + echo substr($string[1], 0, 4); + + + ?> + + \ No newline at end of file diff --git a/types.php b/types.php new file mode 100644 index 0000000..d7338fb --- /dev/null +++ b/types.php @@ -0,0 +1,49 @@ + + + + + + + PHP Types + + +

Types.php

+ $boolean = [true, false]

'; + $boolean = [true, false]; + var_dump($boolean); + echo '
'; + + echo '

$integer = 1

'; + $integer = 1; + var_dump($integer); + echo '
'; + + echo '

$float = 1.5

'; + $float = 1.5; + var_dump($float); + echo '
'; + + echo '

$string = "Jose"

'; + $string = 'Jose'; + var_dump($string); + echo '
'; + + echo '

$array = array("Jose", 1, 1.5)

'; + $array = array('Jose', 1, 1.5); + echo '
';
+        var_dump($array);
+        echo '

'; + + echo '

$object = (object)["fruta" => "pera","manzana", "verdura" => "zanahoria","calabaza"]

'; + $object = (object)["fruta" => "pera","manzana", "verdura" => "zanahoria","calabaza"]; + echo '
';
+        var_dump($object);
+        echo '
'; + + echo '

$null = NULL

'; + $null = NULL; + var_dump($null); + ?> + + \ No newline at end of file From 0b8979117a856bad36c2478a3f8dd9975b6923d7 Mon Sep 17 00:00:00 2001 From: Jose Torres Date: Tue, 20 Dec 2022 18:44:58 +0100 Subject: [PATCH 3/6] update Readme --- phpinfo/README.md => README.md | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) rename phpinfo/README.md => README.md (61%) diff --git a/phpinfo/README.md b/README.md similarity index 61% rename from phpinfo/README.md rename to README.md index aa59fd3..63eabc9 100644 --- a/phpinfo/README.md +++ b/README.md @@ -1,21 +1,19 @@ -# Título del Proyecto +# PHP practice with the Assembler school -PHP practice with the Assembler school - -## Comenzando 🚀 +## Starting 🚀 These instructions will allow you to get a working copy of the project on your premises for development and testing purposes. -### Pre-requisitos 📋 +### Prerequirements 📋 XAMPP software installation -### Instalación 🔧 +### Installing 🔧 - [Guide to install XAMPP](https://www.php.net/manual/es/intro-whatcando.php) @@ -25,7 +23,7 @@ When you have installed XAMPP follow the steps below. -## Ejecutando las pruebas ⚙️ +## Running the tests ⚙️ To view the file, type the following in your browser: @@ -34,19 +32,18 @@ To view the file, type the following in your browser: -## Construido con 🛠️ +## Built With 🛠️ -_Menciona las herramientas que utilizaste para crear tu proyecto_ * [PHP](https://www.php.net/) -## Autores ✒️ +## Authors ✒️ * **Jose Torres** - *Trabajo Inicial* - [88jose](https://github.com/88jose) -* **Assembler Institute of Tecnology** - [assembler-institute](https://github.com/assembler-institute) + From e268a7926e2c65a0c60cd333f4b181ed1dc3d723 Mon Sep 17 00:00:00 2001 From: Jose Torres Date: Tue, 20 Dec 2022 18:46:12 +0100 Subject: [PATCH 4/6] update --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 63eabc9..6a84bf1 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,6 @@ When you have installed XAMPP follow the steps below. ## Running the tests ⚙️ To view the file, type the following in your browser: - #### localhost/folder-name From d8a48300fcff45547500ea1750f1caa3033512d6 Mon Sep 17 00:00:00 2001 From: Jose Torres Date: Tue, 20 Dec 2022 18:48:12 +0100 Subject: [PATCH 5/6] update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6a84bf1..4afb85d 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ To view the file, type the following in your browser: ## Authors ✒️ -* **Jose Torres** - *Trabajo Inicial* - [88jose](https://github.com/88jose) +* **Jose Torres** - [88jose](https://github.com/88jose) From 0620c39e0b231744793bcc5df920194c9be220fb Mon Sep 17 00:00:00 2001 From: Jose Torres Date: Tue, 20 Dec 2022 19:08:22 +0100 Subject: [PATCH 6/6] update --- print.php | 1 + strings.php | 6 ++---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/print.php b/print.php index 4bb980c..c6e3128 100644 --- a/print.php +++ b/print.php @@ -15,6 +15,7 @@ print '

Display variable with print statement: '. $name .'

'; echo '
'; + echo '

Show nested array with print_r statement

'; echo '
';
         $compra = array ('verdura' => array ('pimiento', 'calabaza', 'berengena'), 'fruta' => array ('pera', 'manzana', 'uvas'));
diff --git a/strings.php b/strings.php
index e21982f..cfb8ada 100644
--- a/strings.php
+++ b/strings.php
@@ -9,7 +9,6 @@
 
     

Strings.php

Print a text string: "I am a text string"

'; @@ -39,9 +38,8 @@ echo '

Convert text string to lowercase: $phrase = "Today is a good day";
'; echo strtolower($phrase); - echo '

Get substring of text from array.php file
'; - // primer parametro posicion del array, segundo parametro posicion de la letra y tercer parametro cuantas letras queremos mostrar - echo substr($string[1], 0, 4); + echo '

Get substring of text
'; + echo substr($phrase, 0, 4); ?>