diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..66fff41 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "abusaidm.html-snippets" + ] +} \ No newline at end of file diff --git a/README.md b/README.md index b23c66e..4d952f1 100644 --- a/README.md +++ b/README.md @@ -49,3 +49,8 @@ To deliver this project you must follow the steps indicated in the document: - [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) + + + +Note: +All the comments are spanish/english just to save this code and use it in the future. diff --git a/Transaction.php b/Transaction.php new file mode 100644 index 0000000..66408d9 --- /dev/null +++ b/Transaction.php @@ -0,0 +1,51 @@ + amount = $amount; + $this-> description = $description; +} + +public function addTax(float $rate) +{ + $this->amount += $this->amount * $rate / 100; +} + + + + +public function applyDiscount(float $rate) +{ + $this->amount += $this->amount * $rate / 100; +} + +} + + + + Construction method or magic method y se escribe asi: __ + + +Definicion rapida : class comoSeLlame {var $propiedad y function method()}; +*/ + + + + + + +?> \ No newline at end of file diff --git a/arrays.php b/arrays.php new file mode 100644 index 0000000..92aaa06 --- /dev/null +++ b/arrays.php @@ -0,0 +1,117 @@ + 1, 4 => 1, 19, 3 => 13); +print_r($array); */ + + +/* Multidimensional array +$data = array( + array(1, 2, 3), + "John", + "Jane" + ); + + print_r($data); + +echo $data[0][1]; */ + + + + + +/* Lo que metemos dentro del corchete se llama index o key, pero si no se definen las keys, PhP lo hara automaticamente,empezando en 0, */ + +/* $progranmingLanguages = ['PHP', 'Java', 'Python']; + +$name = 'Gio'; + */ +/* echo $name[1]; + +echo $progranmingLanguages[0]; */ + + +/* Para ver si el item existe y envitar errores podemos usar por ejemplo: +la funcion isset . ideal para saber si existe*/ + +/* var_dump(isset($programingLanguages[0])); +var_dump(isset($programingLanguages[3])); */ + + +/* Y si queremos cambiar pro ejemplo 'Java' por C++? */ + + +/* $progranmingLanguages[1] = 'C++'; */ +/* echo $progranmingLanguages[1]; */ +/* var_dump($progranmingLanguages); +print_r($progranmingLanguages); */ + +/* la mejor manera de verlo seria asi: + echo ''; + */ + + + +/*$progranmingLanguages = ['PHP', 'Java', 'Python']; + +$progranmingLanguages[] = 'C++'; /* Esta es la forma mas sencilla */ +/*array_push($progranmingLanguages, 'C++', 'C', 'GO'); /* Esta es mas complicada */ +/* estas son las dos formas de agreganrelementos al array como el push() de javascript + */ + + + +/* array_pad() - Rellena un array a la longitud especificada con un valor +list() - Asignar variables como si fueran un array +count() - Cuenta todos los elementos de un array o algo de un objeto +range() - Crear un array que contiene un rango de elementos +foreach +El tipo array + +https://www.php.net/manual/es/function.array.php +https://www.youtube.com/watch?v=wLoPGWwMamc */ +?> + + + + + + '8.0', + 'python' > '3.9' +]; + + + +/* echo ''; + +echo $progranmingLanguages['php']; + + +$programingLanguages['go'] = '1.15'; + +echo $programingLanguages; + + + +https://www.youtube.com/watch?v=C8ZFLq24g_A +https://www.php.net/manual/es/function.array.php */ + +?> \ No newline at end of file diff --git a/conditionals.php b/conditionals.php new file mode 100644 index 0000000..e79ef47 --- /dev/null +++ b/conditionals.php @@ -0,0 +1,79 @@ + $Tuesday) { + echo "We are on Monday"; + } + + +$date1 = "10"; +$date2 = "05"; + +if ($date1 > $date2) + echo "We are in October $date1"; +else + echo " We are in May $date2"; + */ + + + + +/* elseif/else if */ +/* $a = 10; +$b = 15; + + +if ($a < $b) { + echo "The current minute is less than 10"; +} elseif ($a > $b) { + echo "The current minute is more than 15"; +} else { + echo "Does not meet any conditions"; +} + + +Switch: */ + + +$x = 8; + + +switch ($x) { + case 1: + echo "The answer is 1"; + break; + case 2: + echo "This answer is 2"; + break; + case 3: + echo "The answer is 3"; + break; + case 4: + echo "The answer is 4"; + break; + case 5: + echo "The answer is 5"; + break; + default: + echo "There is no answer"; +} + + + + +?> diff --git a/dates.php b/dates.php new file mode 100644 index 0000000..0d4dec2 --- /dev/null +++ b/dates.php @@ -0,0 +1,71 @@ + + + + + + + + Document + + + + + + + + + ' ; + +/* echo $currentTime + 5 * 24 * 60 *60; los dias dentro de 5 dias, 5 dias, 24horas..etc */ + +/* echo $currentTime - 60 * 60 * 24; el tiempo de ayer */ + +/* Importante */ +echo date('m/d/Y g:ia ') . '
'; + +/* la g nos da el formato 24h sin ceros, la i los minutos sin ceros y la a nos dice si es A.M o P.M */ + + +/* Otro ejemplo */ +echo date('m/d/Y g:ia ', $currentTime + 5 * 24 * 60 *60 ) . '
'; + +/* Y para cambiar la franja horaria, seria algo asi: */ +date_default_timezone_set('UTC'); + +echo date('m/d/Y g:ia ') . '
'; + + +echo date_default_timezone_get() . '
'; + + +/* Otra cosa importante para convertir 'parse dates' string representation en unidades de tiempo, ejemplo: */ + +echo date('m/d/Y g:ia', mktime(0, 0, 0, 4, 10, null)) . '
'; +/* String to time function */ +echo strtotime('2021-01-18 07:00:00') . '
'; + +/* Mola poder ponerle por ejemplo el tomorrow asi: */ +/* o 'las day of february' o 'second friday of January' etc */ +echo date('m/d/Y g:ia', strtotime('tomorrow')); + + +?> + + + + + \ No newline at end of file diff --git a/functions.php b/functions.php new file mode 100644 index 0000000..b037a0e --- /dev/null +++ b/functions.php @@ -0,0 +1,82 @@ +"; +echo "7 + 13 = " . sum(7, 13) . "
"; +echo "2 + 4 = " . sum(2, 4); */ + + + + +function add_five(&$value) { + $value += 5; + } + + $num = 2; + add_five($num); + echo $num; + + + + + + + + + + + + +/* +https://www.exakat.io/en/top-100-php-functions/ +https://www.youtube.com/watch?v=t9FrpTZm1ds +https://www.php.net/manual/en/functions.internal.php +https://www.php.net/manual/en/functions.user-defined.php +https://www.youtube.com/watch?v=RIPJEgOrVRc + +https://www.php.net/manual/en/indexes.functions.php*/ +?> \ No newline at end of file diff --git a/game/img/1.png b/game/img/1.png new file mode 100644 index 0000000..8ff7cec Binary files /dev/null and b/game/img/1.png differ diff --git a/game/img/BioShock_cover.jpg b/game/img/BioShock_cover.jpg new file mode 100644 index 0000000..76bbe98 Binary files /dev/null and b/game/img/BioShock_cover.jpg differ diff --git a/iterators.php b/iterators.php new file mode 100644 index 0000000..444ad54 --- /dev/null +++ b/iterators.php @@ -0,0 +1,47 @@ + + + */ +foreach (array(1, 2, 3, 4) as &$valor) { +$valor = $valor * 2; +} + + +echo $valor; + + + + +/* */ + + +$numero= 1; +while ($numero <= 10) +{ +echo $numero; +$numero = $numero + 1; +} + + + + +/* */ +$numero= 1; + +do { +echo $numero; +$numero++; /* es lo mismo que $numero = $numero + 1; */ +} while ($numero <= 8); + + + +?> \ No newline at end of file diff --git a/maths.php b/maths.php new file mode 100644 index 0000000..bc5554d --- /dev/null +++ b/maths.php @@ -0,0 +1,37 @@ +"; + + +echo abs(3); +echo "
"; + */ + +//round — Rounds a float + + +/* $num1 = 10; +$num2 = 2.54; + + +echo round($num1/$num2); + */ + + +/* Max() and Min() Functions */ + +/* $array =array(34,21,56,14,33); */ + +//echo max($array); +/* echo min($array); */ + +/* echo rand(); */ + + + + + + + +?> \ No newline at end of file diff --git a/operators.php b/operators.php new file mode 100644 index 0000000..7555bed --- /dev/null +++ b/operators.php @@ -0,0 +1,92 @@ + + + + + + + + */ +$x = 5; +$y = 10; + +if ($x == $y) { + echo "True!"; +} +else { + echo "False!"; +} + +$x = 5; +$y = 10; + +if ($x >= $y) { + echo "True!"; +} +else { + echo "False!"; +} + + + + +/* */ + + + +$x = 10; +$y = 20; + +if ($x == $y or 1 == 1) { + echo "True"; +} + + + + + + +$x = 10; +$y = 20; + +if ($x == $y and 1 == 1) { + echo "True"; +} + + +$x = 10; +$y = 20; + +if ($x == $y || 1 == 1) { /* es igual que Or */ + echo "True"; +} + + + +$x = 10; +$y = 20; + +if ($x == $y && 1 == 1) { /* este es igual que el and */ + echo "True"; +} + +$x = 10; +$y = 20; + +if ($x == $y xor 1 == 1) { /* este significa que solo 1 de las condiciones puede ser True */ + echo "True"; +} + + +?> \ No newline at end of file diff --git a/phpinfo.php b/phpinfo.php new file mode 100644 index 0000000..b851967 --- /dev/null +++ b/phpinfo.php @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/phpinfo/index.php b/phpinfo/index.php new file mode 100644 index 0000000..6480abf --- /dev/null +++ b/phpinfo/index.php @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/print.php b/print.php new file mode 100644 index 0000000..338c595 --- /dev/null +++ b/print.php @@ -0,0 +1,15 @@ + + + + + \ No newline at end of file diff --git a/strings.php b/strings.php new file mode 100644 index 0000000..5463566 --- /dev/null +++ b/strings.php @@ -0,0 +1,62 @@ +'; + +$upper = strtoupper($str); +echo $upper, '
'; + +$ucwords =ucwords($str); //si quieres que todas esten bien, pon el ($lwer); +echo $ucwords, '
'; + + + + +$str = "YES"; + +if(strtolower($str) =='yes'){ +process for yes +} + + +$password = " password "; No pasara por los espacios del ejemplo +if($password == "password"){ + then log them in +} + +if(trim($password) == "password") { En este caso la funcion trim quita los espacios y entonces, si se podra loguear + then log them in +} + +/* TRIM + +trims space offf the beginning of the string +ltrim($password): +trims space off the end of the string +rtrim($password);*/ + + + +$csv = "45,23,78,99,87,"; +//quiero quitar la coma final, remove last comma by using trim function + +echo rtrim($csv,','); +$trimmedCsv = rtrim($csv,','); +$csvArray = explode (',', $trimmedCsv); +var_dump($csvArray); +echo '
'; + + +/* sin comas y tipo array hacia abajo con br */ +foreach($csvArray as $id){ + echo $id, '
'; +} + + + + +//info: https://www.youtube.com/watch?v=SLYSb_IWNTw + +?> \ No newline at end of file diff --git a/types.php b/types.php new file mode 100644 index 0000000..75ccbc2 --- /dev/null +++ b/types.php @@ -0,0 +1,244 @@ +addTax(8); +$transaction->applyDiscount(10); + +var_dump($transaction->amount); + + */ + + + + + /* claass className */ + +/* Property is just another word for variables (llamamos las variables dentro de la clase) +Y los Methods es cuando llamamos las funciones dentro de la clase. */ + +/* { + var $propertyName = value; + function methodName() + +{ + //$this keyword is used to cal properties & methods within the class +$this->propertyName; +$this->methodName(); +} +} */ + +/* $obj = new className; //$obj variable becomes data type object +$obj->methodName(); +$obj->propertyName; */ + +/* Class is like a Template and the real things here are Objects */ +/* +class Game { + + const BR = '
'; + + var $price; + var $name; + var $photo; + var $dir = './game'; + + +public function print_game(){ +echo "
"; +echo "{$this->name}".self::BR; +echo "".self::BR; +echo '$'.$this->price; +echo "name = 'Bioshock Infinite'; +$game->price = 14.99; +$game->photo = './game/BioShock_cover.jpg'; + +$game->print_game(); + + +/* Other example: */ + + +/* + +$game->name = 'The Witcher 3'; +$game->price = 27.89; +$game->photo = 'the-witcher-3.jpg'; + +$game->print_game(); */ + + + +//Info: https://www.youtube.com/watch?v=yrIbbKuSqK8 + + + +/* La manera automatizada de hacer lo de arriba con codigo limpio es algo asi: */ + +/* + +public function set_game($name,$price,$photo){ + $this->name = $name; + $this->price = $price; + $this->photo = $photo; +} + +$game->set_game('Overwatch', 44.99, 'overwatch.jpg'); */ + + + + + +/* NULL */ + + +//Null constant +/* $x = null; +var_dump($x); */ +/* var_dump(is_null($x)); */ +/* var_dump($x === null); */ + + +/* Otro ejemplo: */ + +/* $x = 123; +var_dump($x); + +unset($x); //Esto destroza la variable + +var_dump($x); */ + + + +?> \ No newline at end of file