<?php function mb_ctype_alnum($s){ return preg_match("/^[A-Za-z0-9_öçşğıüÖÇŞİĞÜ.]+$/",$s); } class dogrula{ var $metin_durum=false; function tekKelime($giris,$min_size=false){ $durum = false; if($min_size){ if (mb_strlen($giris) >= $min_size){ if (mb_ctype_alnum($giris)){ $durum = true; } } }else{ if(mb_ctype_alnum($giris) && mb_strlen($giris) > 0) { $durum = true; } } return $durum; } function rakam($giris,$ondalik=false) { $durum=false; if($ondalik){ if(preg_match('/,/',$giris)){ $tmp_giris = explode(',', $giris); }else{ $tmp_giris = explode('.', $giris); } for ($i=0; $i<count($tmp_giris); $i++) { if (ctype_digit($tmp_giris[$i])) { $durum = true; } } }else{ if (ctype_digit($giris)){ $durum = true; } } return $durum; } function eposta($giris){ $durum = false; if (preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/", $giris)) { $durum = true; } return $durum; } function adres($adres){ $regexp = "/^(https?:\/\/)?(([0-9a-z_!~*'().&=+$%-]+:)?[0-9a-z_!~*'().&=+$%-]+@)?((([12]?[0-9]{1,2}\.){3}[12]?[0-9]{1,2})|(([0-9a-z_!~*'()-]+\.)*([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\.(com|net|org|edu|mil|gov|int|aero|coop|museum|name|info|biz|pro|[a-z]{2})))(:[1-6]?[0-9]{1,4})?((\/?)|(\/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+\/?)$/"; if (preg_match( $regexp, $adres )){ if (!preg_match( "/^https?:\/\//", $adres )) $adres = "http://" . $adres; if (!preg_match( "/^https?:\/\/.+\//", $adres )) $adres .= "/"; if ((preg_match( "/\/[0-9a-z~_-]+$/", $adres)) && (!preg_match( "/[\?;&=+\$,#]/", $adres))) $adres .= "/"; return true; }else{ return false; } } function yazi($giris,$cikti=false,$guvenlik=false){ $metin = false; if ($cikti == true) { if (mb_strlen(trim($giris)) > 0) { if ($guvenlik) { $metin = strip_tags($giris); $metin = htmlspecialchars($metin); }else{ if(!get_magic_quotes_gpc()){ $metin = addslashes($giris); }else{ $metin = $giris; } } } }else{ if(mb_strlen(trim($giris)) > 0){ $metin = true; } } return $metin; } } $v=new dogrula; var_dump($v->tekKelime($giris="MerhabaDü2nya",$min_size=false)); echo "<br>"; var_dump($v->rakam($giris="12.3",$ondalik=true)); echo "<br>"; var_dump($v->rakam($giris="12,3",$ondalik=true)); echo "<br>"; var_dump($v->rakam($giris="12",$ondalik=false)); echo "<br>"; var_dump($v->rakam($giris="12",$ondalik=false)); echo "<br>"; var_dump($v->eposta($giris="ulusanyazilim@gmail.com")); echo "<br>"; var_dump($v->adres($adres="https://ulusanyazilim.com")); echo "<br>"; var_dump($v->yazi($giris="<a href=\"\">'Merhaba'</a>",$cikti=false,$guvenlik=false)); echo "<br>"; var_dump($v->yazi($giris="<a href=\"\">'Merhaba'</a>",$cikti=true,$guvenlik=true)); echo "<br>"; var_dump($v->yazi($giris="<a href=\"\">'Merhaba'</a>",$cikti=true,$guvenlik=false)); ?>
Çıktısı
bool(true) bool(true) bool(true) bool(true) bool(true) bool(true) bool(true) bool(true) string(9) "'Merhaba'" string(28) "\'Merhaba\'"