Categories
Friends
Links
Category Archives: PHP
Automatic mailto links
PHP: $string = preg_replace(‘([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})’,‘<a href="mailto:\\1">\\1</a>’, $text); echo $string;
How to make a random number
PHP: function getRandomId($min = NULL, $max = NULL) { if (is_numeric($min) && is_numeric($max)) { return mt_rand($min, $max); } else { return mt_rand(); } }
Posted in PHP Leave a comment
How to make a PHP include
Basic include: <?php include("navigation.php"); ?> Include from the root: <?php $path = $_SERVER[‘DOCUMENT_ROOT’]; $path .= "/common/header.php"; include_once($path); ?>
Get Image Info
PHP: /* * @param string $file Filepath * @param string $query Needed information (0 = width, 1 = height, 2 = mime-type) * @return string Fileinfo */ function getImageinfo($file, $query) { if (!realpath($file)) { $file = $_SERVER["DOCUMENT_ROOT"].$file; } [...]
Posted in PHP Leave a comment
Url Validation
PHP: $url = ‘http://example.com’; $validation = filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED); if ( $validation ) $output = ‘proper URL’; else $output = ‘wrong URL’; echo $output;
How to make an automatic copyright year
PHP: © <?php echo date("Y") ?>
Posted in PHP Leave a comment
Sending Email with PHP
Html form: <form action="" method="post"> <label for="Name">Name:</label> <input type="text" name="Name" id="Name" /> <label for="Email">Email:</label> <input type="text" name="Email" id="Email" /> <label for="Message">Message:</label> <textarea name="Message" rows="20" cols="20" id="Message"></textarea> <input type="submit" name="submit" value="Submit" /> </form> Process with PHP This could be in a seperate file [...]
How to get latest Twitter status