Getting a file extension using PHP
<?php function getExt($filename){ return substr(strrchr($filename, ‘.’), 1); } $file = ‘myphoto.jpg’; echo getExt($file); ?> The output is jpg
Read more<?php function getExt($filename){ return substr(strrchr($filename, ‘.’), 1); } $file = ‘myphoto.jpg’; echo getExt($file); ?> The output is jpg
Read moreWe can match string in PHP using strrpos function here is the sample code <?php function Match($keyword,$subject){ if(strrpos($subject,$keyword)===false){ return false; }else{ return true; } } $keyword = ‘insicdesigns.com’; $subject = ‘I love insicdesigns.com’; if(Match($keyword,$subject)){ echo ‘Match!’; }else{ echo ‘Not found’; } ?> It will display… Match!
Read moreEmail validation is very important in application development. Here I show you a sample PHP code on how to validate email address. <?php function isEmail($email){ if(!eregi(“^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$”, $email)){ return false; }else{ return true; } } $email = ‘test@test’; if(!isEmail($email)){ echo ‘Invalid email address’; }else{ echo ‘Ok’; } ?> The output is… Invalid email address As simple [...]
Read moreThis is the simple function of generating a random numbers in php. <?php function Random($length=5){ $key = ”; $pattern = “12345678901234567890123456789012345678901234567890″; for($i=0;$i
Read more<?php echo ‘Your IP ‘.$_SERVER['REMOTE_ADDR']; ?>
Read more