Recommended:

  • phpclasses.org
  • jsclasses.org
  • jsmag.com
  • siteapps.com
  • View our reviews on Hot Scripts
  • JS Tutorial
  • scripts.com
  • securesignup.com




Recent Comments

Powered by Disqus




Get binary data from file

2012-03-10

Here is a quick example how to get binary data from any file: <?php //call function when contents loaded ob_start("get_bytes"); function to_binary($x, $numbits = 8) { // Convert to binary $bin = decbin($x); $bin = substr(str_repeat(0,$numbits),0,$numbits - strlen($bin)) . $bin; // Split into x 4-bits...

Comments Read more

All files in directory

2011-08-29

Sometimes there is a need to process all files in one directory, for example resize all images or collect all CSS files, minify them and include in on file, and many other practises. Here is a pretty simple way to do it in PHP: <?php //provide path of directory //in this example we'll use this same directory $d = new...

Comments Read more

Dynamically resize or crop images

2011-07-01

Here is a script that will alow you to dynamically resize or crop images. It takes parameters from $_GET variables. You can provide image path, width and height. If width and height is not provided, then images default width and height is used. If only width or only height is provided - image is resized to secified width or height. If both...

Comments Read more

Add watermark on image using PHP and GD2

2011-06-29

Best way to protect your images is to put a watermark with your logo on them, so they've become useless for others. Here is an example of how it can be done. This script takes image path and watermark path, creates blank transparent image resource and copies image and watermark to it. It also shows options of watermark placement in...

Comments Read more

Convert twitter created_at time format to ago format

2011-02-22

Here is a simple PHP function, which can convert created_at time format from twitter API to ago time format (hour ago, week ago, etc) like on twitter website itself. <?php function twitter_time($a) { //get current timestampt $b = strtotime("now"); //get timestamp when tweet created $c = strtotime($a); //get...

Comments Read more

Simple Auto-CMS using HTML pages

2010-11-04

Here is an interesting idea of CMS which is managed by HTML files. It is simple php script, that searches specified location and takes all folders and html files and interprets them as pages and content. Basically, you can manage your content with HTML files, and this script will automatically create menu to browse them. For example,...

Comments Read more

Create blank transparent PNG images using PHP GD functions

2010-10-20

Here is a function to create blank transparent png image for background. This function uses alpha channel information for image transparency (thus available only for PNG).  It takes width and height as a parameters and returns GD image resource: <?php function create_blank($width, $height){ //create image with specified sizes ...

Comments Read more

Generate WORD document using PHP

2010-09-22

There are two ways of generating word document using PHP. First would be using COM object. Other would be by sending headers and outputting HTML code for browser to interpret as word document. So for using COM object, here is an example of how to do it: <?php // Create new COM object – word.application $word = new...

Comments Read more

Get youtube thumbnail

2010-09-14

This function can get thumbnail of youtube video. It takes embed code or link to youtube video as parameter and returns link to thumbnail of that video from youtube server. <?php //you can pass embed code or youtube link function youtube_thumbnail($youtube){ //checking if anything found using embed code expression ...

Comments Read more

Get full URL of current page

2010-09-05

To get full URL of current, you would probably use this code: <?php echo !empty($_SERVER['HTTPS']) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; But, what if you want to modify URL to exclude some parameters, so they won't get added many...

Comments Read more

PHP word wrapping

2010-09-04

There is a built in function wordwrap, that can divide long text into multiple lines by specified character amount, but sometimes that's just not enough. There are situations when you need more custom approach to divide text into multiple lines. For example, when dealing with UTF-8, you should use multi-byte safe functions, plus...

Comments Read more

PHP array rotation

2010-08-29

Here are some functions to change positions of elements values in array, without changing their order, thus making array rotate. These functions do not preserve array keys, only rotating values. This function rotates array values by specified amount of steps. Positive number will make array rotate forward, negative -...

Comments Read more

Multiple curl requests

2010-08-06

Here is function that performs multiple curl requests which is much faster then file_get_contents or single curl request. For more information http://webcodingeasy.com/Site-optimization/Comparing-filegetcontents-with-curl-and-curl-multi-handlers It takes array of URLs to request as a parameter and returns array of contents or errors...

Comments Read more

strpos function for arrays

2010-08-06

Here is a function that checks if any of array values is a substring of a specified string. It takes string as haystack and array of needles and returns false if none of needles appeared in haystack or key of array of first needle that appeared in string: <?php function strpos_arr($haystack, $arr_needle){ $valid = false; ...

Comments Read more

Make first letter of every sentence uppercase

2010-07-27

This function takes text as a parameter and makes first letter of every sentence to the uppercase. You can modify it, to make all string lowercase before making first letter uppercase (if you have whole text in CAPS for example). <?php function sentence_case($string) { //find sentence $sentences = preg_split('/([.?!]+)/',...

Comments Read more

Force file download

2010-07-20

Here is the function to force open/save dialog and not just automatically open files in browser. You can modify it by adding more file extensions. <?php //$file = "/folder/filename.ext"; function force_download($file) { $ext = explode(".", $file); switch($ext[sizeof($ext)-1]) { case 'jar': $mime =...

Comments Read more

Send UTF8 email with attachment

2010-07-20

Here is the function to send email, that can contain UTF8 characters and file attachments. It takes 5 parameters: $to - where to send email, $from - from whom email was sent, $subject - email subject, $message -  message of email, $file - path to file. <?php //$to = "abc@abc.com"; //$from = "admin@web.com"; //$subject = "Welcome to...

Comments Read more

Output buffering

2010-07-14

So why should you use output buffering. First of all, because you can send headers any where in the script without worrying, that headers are sent after output, thus eliminating header error. And next thing you can manipulate with content even after all output done and before it was sent to browser. Here is an example of output buffer...

Comments Read more

List of all $_SERVER variables and values

2010-06-29

Here is the code, that gives you list of all $_SERVER variables and values: <?php echo "<table border='1'>"; foreach($_SERVER as $key => $value) { echo "<tr><td style='width:100px;'>" .$key ."</td>"; echo "<td style='width:600px;'>".$value."</td></tr>"; } echo...

Comments Read more

Generate random string in specified length

2010-06-23

This function generates random string up to 32 characters length. It can be used to generate text for captchas or generate random password, when user wants to reset is. It takes length of string to generate as parameter:  <?php function random_string($length = 0) { $random = md5(uniqid(rand(), true)); if ($length >...

Comments Read more



1 2