Category Archives: PHP

How to get latest Twitter status

PHP:   <?php   function getTwitterStatus($userid){ $url = "http://twitter.com/statuses/user_timeline/$userid.xml?count=1";   $xml = simplexml_load_file($url) or die("could not connect");          foreach($xml->status as $status){        $text = $status->text;        }        echo $text;  }   //my user id kenrick1991 getTwitterStatus("kenrick1991");   ?>  
Posted in PHP | Leave a comment

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;  
Posted in PHP | Tagged , | Leave a comment

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); ?>  
Posted in PHP | Tagged , , | Leave a comment

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;  
Posted in PHP | Tagged , | Leave a comment

How to make an automatic copyright year

PHP:   &copy; <?php echo date("Y") ?>  
Posted in PHP | Leave a comment