<?php
$domin = 'domin.com';
function ping($host, $port, $timeout)
{
$tB = microtime(true);
$fP = fSockOpen($host, $port, $errno, $errstr, $timeout);
if (!$fP) { return "down" }
$tA = microtime(true);
return round((($tA - $tB) * 1000), 0)." ms"
}
echo ping($domin, 80, 10);
?>
<?php
function is_valid_email($email, $test_mx = false)
{
if(eregi("^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)
(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email))
if($test_mx)
{
list($username, $domain) = split("@", $email);
return getmxrr($domain, $mxrecords);
}
else
return true;
else
return false;
}
?>
<?php
function word_count($sentence){
$array = explode(" ", $sentence);
return count($array);
}
$words = word_count("The is a group of words");
echo $words;
?>
<?php
function nCode($code) {
$code = substr($code, 0, 10);
$sum = 0;
for($i = 0; $i < 9; $i++) {
$sum += ((10 - $i) * substr($code, $i, 1));
}
$sum %= 11;
if($sum > 2) {
$sum = 11 - $sum;
}
return ($sum == substr($code, -1));
}
?>
<?php
function file_size($url){
$size = filesize($url);
if($size == 1073741824){
$fileSize = round($size/1024/1024/1024,1) . 'GB';
}elseif($size == 1048576){
$fileSize = round($size/1024/1024,1) . 'MB';
}elseif($size == 1024){
$fileSize = round($size/1024,1) . 'KB';
}else{
$fileSize = $size . ' bytes';
}
return $fileSize;
}
echo file_size('image.jpg');
//بجای image.jpg ادرس فایل رو وارد کنید
?>
<?php
function password_strength($string){
$h = 0;
$size = strlen($string);
foreach(count_chars($string, 1) as $v){
$p = $v / $size;
$h -= $p * log($p) / log(2);
}
$strength = ($h / 4) * 100;
if($strength > 100){
$strength = 100;
}
return $strength;
}
var_dump(password_strength("رمز عبور شما"));
?>
<?php
$visitCounter = 0;
if(isset($_COOKIE['visitCounter'])){
$visitCounter = $_COOKIE['visitCounter'];
$visitCounter ++;
}
if(isset($_COOKIE['lastVisit'])){
$lastVisit = $_COOKIE['lastVisit'];
}
setcookie('visitCounter', $visitCounter+1, time()+3600);
setcookie('lastVisit', date("d-m-Y H:i:s"), time()+3600);
if($visitCounter == 0){
echo "شما اولین بازدیدکننده از این صفحه هستید!"
} else {
echo "تعداد مشاهدهی این صفحه: ".$visitCounter;
echo '
';
echo "زمان آخرین بازدید از این صفحه: ".$lastVisit;
}
?>
<?php
$directory = "C://"
$files = scandir($directory);
echo "<pre>"
print_r($files);
echo "</pre>"
?>