Posts Tagged ‘extension’

Session Restore-Firefox

Wednesday, July 16th, 2008

Firefox, for the most part, is a stable browser. However, even the most stable browsers crash. Firefox 2.0 has a great feature built in called “Session Restore”. With older versions of Firefox you had to install the Session Restore extension to gain this functionality. In the event of a browser crash or accidental v, you are given the option to restore all the tabs and pages that you had open before the browser prematurely closed. This feature alone makes Firefox very attractive.

GOOGLE TOOLBAR

Tuesday, July 15th, 2008

Instead of going to Google.com each time to search, it’s much faster to have Google built into your browser. Several options:

* My preferred browser for PC or Mac is Firefox <getfirefox.com>, which already has built-in Google. You should download the free Googlebar extension <googlebar.mozdev.org> or the official Google Toolbar <toolbar.google.com> (the Google Toolbar also works on PC Explorer). Faster searches; pop-up blocker; highlighting; word find (go directly to a word/phrase on a page). Be sure to get the Cool Iris extension for Firefox, which lets you preview Google results.

Php:Adding an extension

Monday, June 30th, 2008

Problem

You need PHP’s built-in ftp functions for the ultra-cool script you are writing, but your service
provider does not have PHP compiled with the –enable-ftp option.

Solution

If you have a shell account on a system with the same operating system as your web server, grab the
PHP source tarball and build using:

–with-apxs –enable-ftp=shared
You can check which flags your provider used by putting a phpinfo() call in a script on your server.

<?phpinfo()?>
Once compiled, you will find a “modules/ftp.so” file which you can copy to your web server and
enable either by putting:

extension=ftp.so
in your php.ini file or by adding this to the top of your script:

<?php dl(”ftp.so”) ?>

PHP:Use Less PHP And More HTML With Alternative Syntax

Monday, June 30th, 2008

When PHP is tightly intertwined with HTML it can be awful to lay your eyes upon. Many years ago, while with a previous employer, the development staff and I believed it was a sin to use straight HTML in PHP files. We believed every file ending in a .php extension could only contain PHP. In retrospect, I don’t know why we ever did this, but I have seen other groups adhere to such rules as well. This style made what should have been simple HTML far more complex that it had to be.

Over the past few years the style in which developers are writing PHP to output HTML has shifted quite a bit.

Example 1: No Alternative Syntax, and a Lot of PHP.

<?php
echo “<table size=\”100\”>\n”;
echo ” <tbody>\n”;

if($displayResults) {

while($row = mysql_fetch_assoc($result)) { ?>
echo “<tr>\n”;
echo “<td>” . htmlentities($row['id']) . “</td>\n”;
echo “</tr>\n”;
}

}

echo “</tbody>\n”;
echo “</table>\n”;

?>

This is typical to what I’ve seen in a number of PHP applications. Though this is a simple example, I am sure you can appreciate how this method of outputting mostly html can grow out of control. It requires significantly more developer brain power to determine the code’s purpose than the example below.

Example 2: Less PHP Paired With Alternative Syntax

<table>
<tbody>
<?php if($displayResults): ?>
<?php while($row = mysql_fetch_assoc($result)): ?>
<tr>
<td><?php echo htmlentities($row['id']); ?></td>
</tr>
<?php endwhile; ?>
<?php endif; ?>
</tbody>
</table>

Here in example 2 the same functionality is achieved by using PHP alternate syntax and less output statements. As you can see, this fashion of interweaving PHP and HTML can go a long way to increase code readability.

PHP:safe_dl — Safely Load a PHP extension at runtime

Monday, June 30th, 2008

<?php
$extension = “php_domxml”;
var_dump(safe_dl($extension));
/**
* Loads extension safely
*
* Checks whether the extension is already loaded, if so does not try to reload it.
* Depending ot current OS it will try to load “.dll” or “.so” file.
* Some checks are made for GD library.
*
* @param    string    extension the extension that will be loaded
* @author RAJI <raji.peaceful@gmail.com>
* @author RAJI
*/
function safe_dl($extension)
{
$res = 0;
$extension = strtolower(trim($extension));
// if these is an extension supplied remove it
if (($posit = strpos($extension, “.”)) !== false)
$extension = substr($extension, 0, $posit);
// special check for gd1 & gd2
if ($extension == ‘gd’ || $extension == ‘gd2′ )
{
$ar = @gd_info();
if (is_array($ar)
&& !empty($ar["GD Version"])
&& (
// gd1
( ($extension == ‘gd’ && strpos($ar["GD Version"], “1.”) !== false)
||
// gd2
$extension == ‘gd2′&& strpos($ar["GD Version"], “2.”) !== false)
)
)
return true;
else
return false;
}
// if already loading return true
if (!empty($extension)
&& extension_loaded($extension))
return true;
// if not extension not loaded try to load it
if ( !empty($extension) &&
!extension_loaded($extension) &&
( @ini_get(”enable_dl”) == 1 ||
strtolower(@ini_get(”enable_dl”) ) == “on”)
)
{
// depending on OS load appopriate extension
$res = @dl($extension . “.”
. (strpos(strtolower(PHP_OS), “win”) !== false
? ‘dll’
: ’so’));
}
return $res
? true
: false;
}
?>

PHP:get/retrieve file basename,extension,path,dirname

Monday, June 30th, 2008

$file = ‘/dir/some.gif’;
var_dump( pathinfo( $file ) );
Result:
array(3) {
["dirname"]=>
string(4) “/dir”
["basename"]=>
string(8) “some.gif”
["extension"]=>
string(3) “gif”
}
// or
$file_ext = substr($file, strrpos($file,”.”)+1);