Advertisement
Guest User

Untitled

a guest
Mar 10th, 2016
990
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.46 KB | None | 0 0
  1. //functions.php
  2.  
  3. <?php
  4.  
  5. function tabela_emails($emails) {
  6.     echo '<table><tr><th>Email</th><th>Nome</th></tr>';
  7.     asort($emails);
  8.     foreach($emails as $email => $nome) {
  9.         echo '<tr>' . '<td>' . $email . '</td>' . '<td>' . $nome . '</td>' . '</tr>';
  10.     }
  11.     echo '</table>';
  12. }
  13.  
  14. function devolve_maior($num1, $num2, $num3) {
  15.     if(is_numeric($num1) && is_numeric($num2) && is_numeric($num3) ) {
  16.         if($num1 > $num2 && $num1 > $num3) {
  17.             return $num1;
  18.         }
  19.         else if($num2 > $num1 && $num2 > $num3) {
  20.             return $num2;
  21.         }
  22.         else {
  23.             return $num3;
  24.         }
  25.     }
  26.     else {
  27.         return null;
  28.     }
  29. }
  30.  
  31. function inverte_string($str) {
  32.     if(is_string($str)) {
  33.         return strrev($str);
  34.     }
  35.     else {
  36.         return null;
  37.     }
  38. }
  39.  
  40. //php06.php
  41.  
  42. <!DOCTYPE html>
  43. <html>
  44.     <head>
  45.         <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  46.         <title>PHP: Utilização de associativos</title>
  47.     </head>
  48.  
  49.     <body>
  50.         <?php
  51.             $emails = array("joao@mail.pt"=>"João Silva", "jorge@mail.pt"=>"Jorge Pereira", "sonia@mail.pt"=>"Sónia Silva", "ana@mail.pt"=>"Ana Duarte");
  52.  
  53.             foreach($emails as $email => $nome) {
  54.                 echo $email . ' - ' . $nome . '<br>';
  55.             }
  56.  
  57.         ?>
  58.     </body>
  59. </html>
  60.  
  61. //php07.php
  62.  
  63. <!DOCTYPE html>
  64. <html>
  65.     <head>
  66.         <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  67.         <title>PHP: Produção HTML + Funções</title>
  68.     </head>
  69.  
  70.     <body>
  71.         <?php
  72.             $emails = array("joao@mail.pt"=>"João Silva", "jorge@mail.pt"=>"Jorge Pereira", "sonia@mail.pt"=>"Sónia Silva", "ana@mail.pt"=>"Ana Duarte");
  73.  
  74.             tabela_emails($emails);
  75.  
  76.             function tabela_emails($emails) {
  77.                 echo '<table><tr><th>Email</th><th>Nome</th></tr>';
  78.                 asort($emails);
  79.                 foreach($emails as $email => $nome) {
  80.                     echo '<tr>' . '<td>' . $email . '</td>' . '<td>' . $nome . '</td>' . '</tr>';
  81.                 }
  82.                 echo '</table>';
  83.             }
  84.         ?>
  85.     </body>
  86. </html>
  87.  
  88. //php08.php
  89.  
  90. <!DOCTYPE html>
  91. <html>
  92.     <head>
  93.         <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  94.         <title>PHP: Inclusão Ficheiros</title>
  95.     </head>
  96.  
  97.     <body>
  98.         <?php
  99.  
  100.             require_once('include/functions.php');
  101.             $emails = array("joao@mail.pt"=>"João Silva", "jorge@mail.pt"=>"Jorge Pereira", "sonia@mail.pt"=>"Sónia Silva", "ana@mail.pt"=>"Ana Duarte");
  102.             tabela_emails($emails);
  103.  
  104.         ?>
  105.     </body>
  106. </html>
  107.  
  108. //php09.php
  109.  
  110. <!DOCTYPE html>
  111. <html>
  112.     <head>
  113.         <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  114.         <title>PHP: Funções Numéricas</title>
  115.     </head>
  116.  
  117.     <body>
  118.         <?php
  119.  
  120.             require_once('include/functions.php');
  121.             $numero = devolve_maior(10,3,6);
  122.  
  123.             echo $numero;
  124.  
  125.         ?>
  126.     </body>
  127. </html>
  128.  
  129. //php10.php
  130.  
  131. <!DOCTYPE html>
  132. <html>
  133.     <head>
  134.         <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  135.         <title>PHP: Funções de Strings</title>
  136.     </head>
  137.  
  138.     <body>
  139.         <?php
  140.  
  141.             require_once('include/functions.php');
  142.             $string_invertida = inverte_string("MARIA");
  143.  
  144.             echo $string_invertida;
  145.  
  146.         ?>
  147.     </body>
  148. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement