<?php// $stuff$stuff = ”;for( $i = 1; $i <= 10; $i++ ) { $i_am = ( $i&1 ) ? ‘odd’ : ‘even’ ; $stuff = ‘<p>’ . $i . ‘ I\’m ‘ . $i_am . ‘.</p> ‘; } print $stuff;
Category: PHP Toppings
PHP Toppings
.htaccess – Denied
by admin •
Every wanted to keep everyone out of a directory? Make your .htaccess file this way: deny from all Now that entire directory is ‘blocked’ from prying eyes. How about not allowing any site visitor from parsing a resource? It goes a little like this: <Files *.phpi> deny from all </Files> Now any file with the…
PHP Toppings
HTACCESS Re-Direct A Single Directory
by admin •
This will work to re-direct a single directory to a new location: # Permanent move Redirect 301 /directory/ http://newlocation.com
PHP Toppings
HTACCESS Re-Direct Entire Site to New Location
by admin •
You need to re-direct an entire site to a new location? This will do it: # Permanent move Redirect 301 / http://newsite.com
PHP Toppings
HTACCESS re-direct to WWW Version of Site
by admin •
.htaccess to redirect dynamically to to the www version of the domain if the non-www version is requested: RewriteCond %{HTTP_HOST} ^([a-z-]+)\.([a-z]{2,6})$ [NC] RewriteRule ^(.*)$ http://www.%1\.%2/$1 [R=301,L]
PHP Toppings
Alphabetize an Array
by admin •
Reading a directory and putting the files found into an array shouldn’t be such a big deal, right? How about alphabetizing that array? function read_a_directory( $DIR ) { if ( is_dir( $DIR ) ) { if ( $dh = opendir( $DIR ) ) { while ( ( $file = readdir( $dh ) ) !== false…
PHP Toppings
Alternating
by admin •
There are dozens of ways to alternate. The most common and visible is the background colour of your tabular data. I use PHP to generate my HTML and the following are my two favourites: foreach( (array)$results AS $K => $V ) {$alt = ( $alt == ‘odd’ ) ? ‘even’ : ‘odd’ ;} This works…
PHP Toppings
Week attempts at comedy for a very small audience:
by admin •
In life being type cast is not always a good thing. In PHP ‘typecasting’ can be a very good thing.
PHP Toppings
Simple Iteration
by admin •
Jamie came across this beauty: foreach ((array)$myArray as $key => $val) { // Whatever code here. } Never get caught again without an array.