28 January 2012

redirect domain.com to www.domain.com using .htaccess

RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=permanent,L]

sort by occurence of anyvalue in a column

SELECT * , COUNT( ref ) AS occurances FROM table GROUP BY ref ORDER BY occurances DESC

count the occurence of a word in a string

<?php
$str="hi how how r you how?";
echo substr_count($str, 'how');
?>

this will give outpus as "3"
since "how" occured in the string 3 times.