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




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

Create thumbnails for image files

2010-05-27

This function creates thumbnails for images. It takes image path with file name, thumbnail width, thumbnail height and path where to save thumbnail as parameters. <?php function thumb($path, $width = 120, $height = 100, $dest = "./thumbs") { //getting image sizes $img_sizes = getimagesize($path); //sizes for calculation ...

Comments Read more

Resizing image files

2010-05-27

This PHP function is to resize image in proportion between old size and new specified size without loosing much of image quality.  It determines if image is landscape oriented, portrait or square and resizes image accordingly. Function takes path to image, new width and new height as parameters. <?php function...

Comments Read more

Image file print function

2010-05-24

In PHP you can automatically get width and height of image file, so you don't have to write it manually. You can use this function to output your image in HTML code: <?php function print_image($imagepath) { $img_sizes = getimagesize($imagepath); $width = $img_sizes[0]; $height = $img_sizes[1]; echo "<img...

Comments Read more

Split unicode string into array of letters

2010-05-23

This function allows you to split strings with unicode characters into array with single letters as elements. <?php header('Content-Type:text/html; charset=UTF-8'); function uni_strsplit($string, $split_length=1) { preg_match_all('`.`u', $string, $arr); $arr = array_chunk($arr[0], $split_length); $arr =...

Comments Read more

PHP handling file uploads

2010-05-19

Here is a function to handle file upload, by checking it to bad and forbidden characters and renaming it if file already exists on server: <?php function handle($arr, $dest) { //list of forbidden characters $clist = array("!", "@", "#", "$", "%", "^", "&", "*", "{", "}", "|", "'", ...

Comments Read more

TTF to GD

2010-05-15

How many times you've found a good looking font, but couldn't use it because it was a True Type Font and no GD font which PHP uses. You can convert ttf fonts to gdf wants using this program: http://www.wedwick.com/wftopf.exe or using this site: http://www.lunar.lu/ttf-to-gdf/convert.php

Comments Read more

Display users online without database

2010-05-01

How to display users online without storing sessions in database? Simple, just count how many session files there are in session folder. No database required. Just change session path if you are on a shred hosting (you don't want to display all users from all websites) and call this simple function: <?php //change sessions path if you...

Comments Read more

function br2nl()

2010-04-17

I bet you know about nl2br(), when you enter text in <textarea> element and then want to display contents of it as HTML, to get same line breaks, you'll have to use nl2br function. But what i you want to do completely opposite? You have text with different <br>, <br/> <br />  tags and you want to display it in...

Comments Read more

Crop data from database or Read more feature

2010-04-13

So, for example, you have blog with news, and you want to do a preview page with all the news cut to 250 characters and Read more link at the end of each preview. To make it more difficult, you have this data with HTML code and unicode characters, so you can't cut in the middle of unicode char. This function will...

Comments Read more

Measuring PHP script execution time

2010-04-07

To measure script execution time we need to get time when script started, time when ended and do simple math. To do that we put this code in the beginning of PHP script: <?php $time = microtime(); $time = explode(' ', $time); $start = $time[1] + $time[0]; ?> And this one in the end: <?php $time =...

Comments Read more

Simple recursive function to print out database tree structure

2010-04-04

Simple function for database model ID, name, parent, where ID is unique identifier, name - any needed attributes etc, parent - unique identifier of parent where this element is attached to. I am just using my mysql class, you will have to modify it to yours <?php function print_menu($id = 0) { // get all records from database whose...

Comments Read more



1 2