PHP, which stands for “Hypertext Preprocessor”, is a server-side, HTML embedded scripting language used to create dynamic Web pages. Much of its syntax is borrowed from C, Java and Perl with some unique features thrown in. The goal of the language is to allow Web developers to write dynamically generated pages quickly.

PHP: How to create unique short string IDs with PHP & MySQL

  • Post category:PHP
  • Post comments:2 Comments

PHP: How to create unique short string IDs with PHP & MySQL
PHP: How to create unique short string IDs with PHP & MySQL

IDs are often numbers. Unfortunately there are only 10 digits to work with, so if you have a lot of records, IDs tend to get very lengthy. For computers that’s OK. But human beings like their IDs as short as possible. So how can we make IDs shorter? Well, we could borrow characters from the alphabet as have them pose as additional numbers…. Alphabet to the rescue!

I created this function a long time ago. Time to be nice and share.

More is Less – the ‘math’

The alphabet has 26 characters. That’s a lot more than 10 digits. If we also distinguish upper- and lowercase, and add digits to the bunch or the heck of it, we already have (26 x 2 + 10) 62 options we can use per position in the ID.

Now of course we can also add additional funny characters to ‘the bunch’ like – / * & # but those may cause problems in URLs and that’s our target audience for now.

OK so because there are roughly 6x more characters we will use per position, IDs will get muchshorter. We can just fit a lot more data in each position.

This is basically what url shortening services do like tinyurl, is.gd, or bit.ly. But similar IDs can also be found at youtube: http://www.youtube.com/watch?v=yzNjIBEdyww
(more…)

Continue ReadingPHP: How to create unique short string IDs with PHP & MySQL

CakePHP – jQuery Autocomplete Tutorial

CakePHP – jQuery Autocomplete Tutorial
CakePHP – jQuery Autocomplete Tutorial

In this tutorial, i will show you how to implement jQuery UI’s autocomplete widget in cakephp. The script in this tutorial is copy paste from tutorialzine article “A Simple Movie Search App w/ jQuery UI” . We are using a MySql database containing a users table. When you start typing a user name in the text box of the search form, an AJAX request is sent to controller. The controller returns a JSON object with suitable user name.

This is what we’re going to create:

CakePHP – jQuery Autocomplete Tutorial
CakePHP – jQuery Autocomplete Tutorial

(more…)

Continue ReadingCakePHP – jQuery Autocomplete Tutorial

PHP: Adding Parameters To A URL in PHP

  • Post category:PHP
  • Post comments:0 Comments

PHP: Adding Parameters To A URL in PHP
Adding Parameters To A URL in PHP

This article shows how to add query parameters to a URL in a php script. It is aimed at the beginner to intermediate level PHP programmer but developers from other languages may find some useful information here. At first this seems like a simple enough task. Starting with the url as a string, just add the new parameters to the end. Yeah, that would be nice. It turns out that there are a few conditions that make the process just a bit more difficult. It’s still not a hard problem but there are enough special cases to make it interesting.
(more…)

Continue ReadingPHP: Adding Parameters To A URL in PHP