htaccess Rewrites SEF URL and submits to PHP
- Category: Personal Home Page
- Hits: 25632
A quick note on a htaccess rewrite rule I'm liking.
What does it do?
What I type:
http://www.mywebsite.com/blog/videos.htmlSends this to server:
http://www.mywebsite.com/index.php?myFolder=blog&myFiles=videosHow?
Preg_Replace all strings between two tags
- Category: Personal Home Page
- Hits: 58119
For those of you who use Preg_Replace. Preg_replace is a function that uses regular expressions to search and replace a string.
Why?
Because my understanding with regular expressions is shady and varies from language to language, I've written this article as a quick reference point.
How?
Php convert filesizes to bytes kb mb gb
- Category: Personal Home Page
- Hits: 22135
Just a quick note on how to format a given filesize and to reduce the display output to a small string, eg:
196 bytes : displays as => "196 bytes" 12945 bytes : displays as => "12 Kb" 1478515 bytes : displays as => "1 Mb" 8798745455 bytes : displays as => "8 Gb"
Convert seconds to total time in PHP
- Category: Personal Home Page
- Hits: 13251
This is intended for activity/session durations and although I usually get MySQL to do the date/time calculations, there are times when we have to do with PHP. This is the shortest way I know to properly convert seconds into total hours, minutes and seconds (taking into account regional settings and without using a date function).
How?
$total_time =intval(intval($total_seconds)/ 3600).":"; $total_time.=str_pad(intval(($total_seconds/60)%60),2,"0",STR_PAD_LEFT).":"; $total_time.=str_pad(intval($total_seconds%60),2,"0",STR_PAD_LEFT); // yields // 82800 = 23:00:00 // 108000 = 30:00:00On one line:
$total_time=intval(intval($total_seconds)/ 3600).":".str_pad(intval(($total_seconds/60)%60),2,"0",STR_PAD_LEFT).":".str_pad(intval($total_seconds%60),2,"0",STR_PAD_LEFT);
First and Last Entry on a Page using Modulus Remainder
- Category: Personal Home Page
- Hits: 19729
This article is a quick note (so I never spend as long again) in PHP on how to determine when looping through a loop, which entry was first and which was last. This is incredibly useful for pagination.
PHP & MySQL Search Engine
- Category: Personal Home Page
- Hits: 45591
So we want to give a search engine to our users. This sounds really simple, we could try:
$search_term_esc = AddSlashes($search_term); $sql = "SELECT * FROM Content WHERE content_body LIKE '%$search_term_esc%'";Great! Few problems though, multiple terms are not supported; quotation marks and apostrophes may be an issue;
UTF8 Unicode PHP MySQL for International Characters
- Category: Personal Home Page
- Hits: 30762
- Joomla works fine with international characters
- A Module Extension I wrote for Joomla! displayed funny characters.
- The Joomla! articles were displaying the correct characters for that language set.
- I needed to make my extension read data from a MySQL database and display the caracters as intended with UTF8.
I tried enough extensions and forum solutions, and although these changes would have an effect on the module (such as take away accents and convert to ASCII), they weren't what we were looking for.
The quick solution was to make the script run a MySQL command at the start:
SET NAMES 'utf8'Now I need to run this command from within a Joomla! extension using the mysql Joomla! classes, here's how I've used in this script pulling IDs and titles from the a sample table:
Yesterday's time in PHP
- Category: Personal Home Page
- Hits: 8253
$today=date("Y-m-d");
$yesterday = date('Y-m-d', mktime(0, 0, 0, date("m") , date("d") - 1, date("Y")));

