All Posts in PHP

How to add even and odd classes to posts

First declare this variable before your while or foreach loop: <?php $j = ''; ?> Then paste this code within the class attribute of your element within the loop: <?php echo (++$j % 2…

Super Easy Way to Display an RSS Feed with PHP

Easy as pie: http://bavotasan.com/2010/display-rss-feed-with-php/…

301 Redirect with PHP

<?php // 301 Redirect - if url contains www then redirect to non-www $current_path = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; if ( strpos($current_path,'www.') !== false ) { …

Simple Way to Get File Extension

<?php $file = 'file.txt'; function getFileextension($file) { return end(explode(".", $file)); } ?> Source: http://css-tricks.com/snippets/php/find-file-extension/…

How-to Write to Text Files on Server

Create a text file (in this case we’ll name it test.txt) Make it writable (permissions: 0777) PHP Code: <?php function writeToFile(){ // 'w' overwrites entire file whereas 'a' appe…