Latest web development tutorials
×

PHP corso

PHP corso PHP breve introduzione PHP installare PHP grammatica PHP variabile PHP echo/print PHP Tipi di dati PHP costante PHP stringa PHP operatori PHP If...Else PHP Switch PHP schieramento PHP Ordinamento di un array PHP superglobals PHP While circolazione PHP For circolazione PHP funzione PHP Variabili magici PHP Namespace PHP Object-Oriented

PHP modulo

PHP modulo PHP Forms Authentication PHP modulo - I campi obbligatori PHP modulo - e-mail di verifica e l'URL PHP esempio forma completa PHP $_GET variabile PHP $_POST variabile

PHP Tutorial avanzato

PHP array multidimensionali PHP data PHP contenere PHP file PHP File Upload PHP Cookie PHP Session PHP E-mail PHP sicurezza E-mail PHP Error PHP Exception PHP filtro PHP Filtro avanzato PHP JSON

PHP 7 nuove funzionalità

PHP 7 nuove funzionalità

PHP Database

PHP MySQL breve introduzione PHP MySQL collegamento PHP MySQL Creazione di un database PHP MySQL Creare una tabella di dati PHP MySQL inserire i dati PHP MySQL Inserire più dati PHP MySQL prepared statement PHP MySQL leggere i dati PHP MySQL WHERE PHP MySQL ORDER BY PHP MySQL UPDATE PHP MySQL DELETE PHP ODBC

PHP XML

XML Expat Parser XML DOM XML SimpleXML

PHP & AJAX

AJAX breve introduzione AJAX PHP AJAX Database AJAX XML AJAX ricerca in tempo reale AJAX RSS Reader AJAX voto

PHP Manuale di riferimento

PHP Array PHP Calendar PHP cURL PHP Date PHP Directory PHP Error PHP Filesystem PHP Filter PHP FTP PHP HTTP PHP Libxml PHP Mail PHP Math PHP Misc PHP MySQLi PHP PDO PHP SimpleXML PHP String PHP XML PHP Zip PHP Timezones PHP Elaborazione immagini PHP RESTful

PHP Forme - messaggio di verifica e URL

Questa sezione descrive come verificare i nomi (nome), e-mail (spam), e gli URL.


PHP - verificare il nome

Il seguente codice sarà un modo semplice per rilevare se il nome del campo contiene lettere e gli spazi, se il valore del campo nome non è legittimo, emette un messaggio di errore:

$name = test_input($_POST["name"]);
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
  $nameErr = "只允许字母和空格"; 
}
nota preg_match - Eseguire un match espressione regolare.

sintassi:

int preg_match (string $ pattern, string $ soggetto [, array $ partite [, int $ bandiere]])


Essere modello soggetto stringa di ricerca che corrisponde all'espressione regolare data contenuti. Se un match, poi i risultati della ricerca saranno riempiti. $ matches [0] conterrà il testo di tutto il modello corrisponde, $ matches [1] conterrà le prime parentesi sotto-modello catturati testo corrispondente, e così via.


PHP - messaggio di verifica

Il seguente codice sarà un modo semplice per rilevare l'indirizzo e-mail è valido. Se l'indirizzo e-mail non è valido, l'uscita di un messaggio di errore:

$email = test_input($_POST["email"]);
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email)) {
  $emailErr = "非法邮箱格式"; 
}

PHP - convalidare l'URL

Il seguente codice rileverà l'URL è legittima (in seguito regolare funzionamento URL espressione contiene un trattino: "-"), se l'indirizzo URL non è valido, emette un messaggio di errore:

$website = test_input($_POST["website"]);
if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website)) {
  $websiteErr = "非法的 URL 的地址"; 
}

PHP - verificare il nome, e-mail e URL

Codice come segue:

<?php
// 定义变量并默认设置为空值
$nameErr = $emailErr = $genderErr = $websiteErr = "";
$name = $email = $gender = $comment = $website = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
   if (empty($_POST["name"])) {
      $nameErr = "Name is required";
      } else {
         $name = test_input($_POST["name"]);
         // 检测名字是否只包含字母跟空格
         if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
         $nameErr = "只允许字母和空格"; 
         }
     }
   
   if (empty($_POST["email"])) {
      $emailErr = "Email is required";
   } else {
      $email = test_input($_POST["email"]);
      // 检测邮箱是否合法
      if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email)) {
         $emailErr = "非法邮箱格式"; 
      }
   }
     
   if (empty($_POST["website"])) {
      $website = "";
   } else {
      $website = test_input($_POST["website"]);
      // 检测 URL 地址是否合法
     if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website)) {
         $websiteErr = "非法的 URL 的地址"; 
      }
   }

   if (empty($_POST["comment"])) {
      $comment = "";
   } else {
      $comment = test_input($_POST["comment"]);
   }

   if (empty($_POST["gender"])) {
      $genderErr = "性别是必需的";
   } else {
      $gender = test_input($_POST["gender"]);
   }
}
?>

esempio »Esecuzione