I maintain a repository for useful PHP functions and classes. The majority of code here is the result of frequent questions, or problems asked on IRC channels, or on the php.net user notes.
All code published here resides in the Public Domain, you are free to modify, distribute or resell this code however you wish. All code is also available on github.com.
» Converting arrays to human readable tables
array2table() allows you to quickly display the contents of an array as a HTML table. It can also recursively display data for nested arrays.
» Converting HTML colours from HEX to RGB
hex2rgb() converts HTML hexadecimal colour codes into their RGB equivalent
» Quickly converting a MySQL timestamp to a Unix Timestamp
mysql2unixtime() converts MySQL timestamps to unix timestamps
» Recursively copying directories in PHP
copyr can be used to copy a file, or recursively copy a folder and its contents.
» Calculating a directories size in PHP
dirsize provides a heavily optimised method for calculating the size of large directories.
» Searching for files in the include_path
file_exists_incpath() checks whether a file exists anywhere along your include_path.
» Recursively deleting directories via FTP
ftp_rmdirr() allows the deletion of whole directory trees on remote servers via FTP.
» Viewing binary data as a hexdump in PHP
hexdump() allows you to dump a binary data stream into a human-friendly format.
» Quick JavaScript email obfuscation
mail_obfuscate allows you to quickly obfuscate an email address in JavaScript to prevent spambots harvesting the address.
» Recursively creating directory structures
mkdirr allows you to create whole directory trees independent of what folders exist in the path.
» Outputing a MySQL result in a HTML table
mysql_draw_table() outputs a MySQL result set as a HTML table.
» Recursively deleting a folder in PHP
rmdirr() allows the deleting of a folder, along with the folders contents.
» Human readable file sizes
size_readable() converts a number of bytes into human readable form.
» Creating a string exerpt elegantly
str_chop() provides a number of options for trimming long text into something suitable for display.
» Highlighting a search string in HTML text
str_highlight() provides a variety of text highlighting options for plaintext or HTML strings.
» Quick and easy random string generation
str_rand() provides a quick wrapper for customised random string output.
» Handling tab to space conversions
tab2space() converts tabs to the appropriate amount of spaces to preserving formatting.
» Improved PHP syntax highlighting
PHP_Highlight uses PHP’s built in tokenizer to provide reliable syntax highlighting for PHP code when server-side highlighting is required.
» Making time periods readable
time_duration() is a flexible function for making time periods readable.
» Cycling between strings, a novel implementation
Cycle provides a novel way to iterate through an array. This is commonly used for zebra-striping tables.
» Retrieve time from an NTP server
ntp_time() allows you to quickly retrieve the time from an NTP server as a unix timestamp.
48 Responses
Wow great work!!
I am web designer and php learner, using php/mysql for one web site. Your sample coder here are clean and easy to understand.
Keep it up!
Abhijeet
very good
thanks for the opensource-work from you!
nice site
nice site!!! you should make your php repository script open source too…lol
Great Site!!!! GREAT resources !!!
Thank you !!
Great code – you really know your stuff. I may use some of your functions on my site in the future. Thanks for all your hard work.
Very nice code and well organized repository… I have learned a fair bit by looking at the code you have written.
Thank You
the resources you provide here are extremly useful. they’ve helped me twice now, and I’m very thankful for these well working solutions.
thanks!
Would be great if you put your Repository Script online too.
Clean and Lean, good ‘work’!
Great site!
I’m bookmarking your site. Keep up the good work!
Absolutely loved the copyr() function! What a lot of work that saved me.
Good!!!
Thanks ..
Cool repository. Was here to see str_highlight. If your repository code also becomes open source, I’ll use it
thanks for your str_rand-function, it saved losts of work and time
I’ll implement it in my forum, that i’m working on. (i want to have a random string, to get an emailadress confirmed
greez
schlimmchen
Hi Aidan
Your site is really cool, with a lot of usefull stuff. And the most important: it’s incredible easy to read / learn / understand your work. Whar about a nice class to read / modify xml files, somthing like simplexml, but for before php 5?
Keep up the good work!
thank a lot!
so nice script
Very nice website! I love your work! Congrats!
Great site!
Thanks
Very good! simple and easy to understand! helpful to me! thanks…
Really nice work with the scripts!
Keep up the good work
respect.
BRAVO!
thx
wah, contentnya bagus bgt. Saya suka trik-trik yang ada di site ini. Teruskan perjuanganmu.all of php-lover waiting for your next ideas…
wow, this site rocks. I am allready using 2 of your cool functions. Keep up the good work !
nice repositary…it’s a great help…thanks
Absolutely beautiful!!! Thanks
Salut, je debute en php aussi et ton site m’en apprend beaucoup. Tes scripts sont clair, efficaces et professionnels.
Ficitation !
Anytime now aidan…hehe
Wow, very impressive aidan!
This works really well
Very nice code repository.
I’ve used (and credited) a piece of your highlighting script for my weblog (http://agilo.acjs.net/).
Besides that, I’ve looked through some of your other codes.
Just wanted to let you know that I like your work.
thanx!
Hi Aidan!
At first, you did a great job. Your functions and classes are very usefully!
Greeting
Daniel Kressler
Bruv, u are a genius. Been looking for a way to solve the directory size problem and alas after searching the whole planet!! i found ur code snippet, was really helpful. Had a few bugs but got my head round it and it certainly worked. You highly regarded, sir!! BEEN a php novice, been programming in php for about 3 months and i have def learnt from u! Hope i can pass on my knowledge to others! Thanks and GOD BLESS!!
Nice sait, thanx for info.
I wish I found this repository code earlier – we recreated the wheel at PHPBee.com
My nick on freenode’s ##php channel is jiggster, so I’m sure you’ve heard of me Aidan. I’ve bugged you more than once (and not just about PHP). Anyways, just dropping by to say hello, and see how things are going on your repository. Did I ever tell you how nice this repository looks? The code is great too, so good work, and such and such.
I just found this site. Very clean and understandable. Congratulations.
No comments on the most important page here? I was so happy to find these great functions, and just I was about to copy paste some, I noticed the “view license” link. I suddenly thought, OK great, this is going to be GPL or something and I’m going to have to create my own functions, but I am very happy to see it’s public domain.
Thanks Aidan!
Thanks Aidan for your good job.
I used it to do advanced calculations on a supplied text string. Thank you for the clean function.
The duration class was a great help to me. Thanks!
Thanks for sharing. Your code is top notch! Keep up the great work.
Hi Aidan,
Thank you for sharing your code repository.
We are expecting more…
Keep up good work.