Quantcast
Channel: Program & Design » PHP
Browsing latest articles
Browse All 10 View Live

PHP string ends with

There’s a hundred ways to do this, but here’s the one I came up with. It doesn’t use regex’s so it should be pretty quick. function ends_with($str, $suffix) {     return substr($str, -strlen($suffix))...

View Article



Hash/unhash HTML

Here’s a little class I wrote that lets you hash HTML and other things so that you can do some processing on just the text, and then unhash the HTML again. class ht {         static $hashes = array();...

View Article

PHP code for handling recursive categories/hierarchical data

I’m just going to paste the code I wrote here… you can read some other tutorial to understand what it’s doing, but for some reason they have really incomplete examples, so here’s the whole shabang. It...

View Article

Get Domain & Subdomain from URL

preg_match('/^(?:www\.)?(?:(.+)\.)?(.+\..+)$/i', $_SERVER['HTTP_HOST'], $matches); define('PROTOCOL', strtolower(substr($_SERVER['SERVER_PROTOCOL'],0,strpos($_SERVER['SERVER_PROTOCOL'],'/'))).'://');...

View Article

Facebook PHP API: Get the names of all your friends

If you didn’t already know, Facebook has an API that exposes quite a darn bit information. You can easily query this data using their API, but each request takes a fair bit of time. Typically, to get...

View Article


SQL Injection Safe Queries Redux

function mysql_safe_string($value) {     if(is_numeric($value))      return $value;     elseif(empty($value))       return 'NULL';     elseif(is_string($value))   return...

View Article

array_map_recursive

Not much needs to be said here. function array_map_recursive($callback, $arr) {     $ret = array();     foreach($arr as $key => $val) {         if(is_array($val)) $ret[$key] =...

View Article

Human Readable File Size in PHP

public static function iec_file_size($size, $digits=4, $unit=0) {     $units = array('B','KiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB');     while($size >= 1024) {         $size /= 1024;...

View Article


PHP: Generate a unique filename for a given directory

This function will generate a filename unique to specified directory. If you’re using it to create filenames for uploaded images, for example, you can give it a path to your upload folder an extension...

View Article


Compile all Jade files to a single client-side JavaScript file

Jade is “a high performance template engine heavily influenced by Haml and implemented with JavaScript for node”. One of it’s nice features is that it lets you compile your Jade templates into...

View Article
Browsing latest articles
Browse All 10 View Live




Latest Images