PHP and Web Technologies Freak
I can’t blog much cuz of my works. I’m pretty busy in these days. When i check php.net, i saw PHP 5.3 released post in 30 Jun -.- nevermind. After a long string of delays, PHP 5.3 is finally out. On the course of last 2 years, I was pretty sure a number [...]
This article explains 2 simple commands that most people want to know when they are using Linux. You can find the size of a directory and find the amount of free space, which is on your computer. The command you use to specify the directory size is “du”. And, to the free space you can [...]
Another simple trick;
$timestamp="1243949621";
echo date("d-m-Y", $timestamp); //02-06-2009
Here’s an easy to use function to copy entire directories
function dir_copy($src,$dst) {
$dir = opendir($src);
@mkdir($dst);
while(false !== ( $file = readdir($dir)) ) {
if (( $file != ‘.’ ) && ( $file != ‘..’ )) {
[...]
Simple and clear;
substr_replace($string ,"",-1);
we’ll go it with get_defined_vars() function. get_defined_vars returns multidimensional array with all defiend variables in PHP
here we go ;
if you want to backup and restore your big MySQL databases you need better solution than phpmyadmin
So here we go;
To dump all databases to a file:
$ mysqldump -u dbuser -pdbpass –all-databases > all-databases.sql
To dump a single database to a file:
$ mysqldump -u dbuser -pdbpass somedb > somedb.sql
Dump InnoDB in a single transaction:
$ mysqldump [...]
There are several methods get a file extension using PHP:
<?
$filename = ‘myfile.jpg’;
// 1. The "explode/end" method
$ext = end(explode(’.', $filename));
// 2. The "strrchr" method
$ext = substr(strrchr($filename, ‘.’), 1);
// 3. The "strrpos" method
$ext = substr($filename, strrpos($filename, ‘.’) + 1);
// 4. The "preg_replace" method
$ext = preg_replace(’/^.*\.([^.]+)$/D’, ‘$1′, $filename);
// 5. The "never use this" method
// From: http://php.about.com/od/finishedphp1/qt/file_ext_PHP.htm
$exts [...]
I spend a lot of time lurking in the channel # PHP (EFnet and freenode, please – no flame wars) and this issue is a frequently asked that the rule is a simple answer in the form of the use of strpos (), or best to ip2long () in a more than less than reply.
Unfortunately, [...]
Here is the way of quick sort in associative arrays;
<?
function qsort($a,$f) {
qsort_do(&$a,0,Count($a)-1,$f);
}
function qsort_do($a,$l,$r,$f) {
if ($l < $r) {
qsort_partition(&$a,$l,$r,&$lp,&$rp,$f);
[...]