Jeffery Vaska has “10 Tips That Every PHP Newbie Should Know“, a nice collection of tips for a newbie venturing into PHP. Tips like MySQL Connection Class, Dealing with Magic Quotes etc can be found there.
Archive for the 'PHP' Category
The following code is basically JS, but has been made into a PHP function so that it could be invoked with different parameters as per our needs.
<?php
function js_redirect($url, $seconds=5) {
echo “<script language=\”JavaScript\”>\n”;
echo “<!– hide code from displaying on browsers with JS turned off\n\n”;
echo “function redirect() {\n”;
echo “window.location = \”" . $url . “\”;\n”;
echo “}\n\n”;
echo “timer = setTimeout(’redirect()’, ‘” . ($seconds*1000) . “‘);\n\n”;
echo “–>\n”;
echo “</script>\n”;
return true;
}
js_redirect(http://blogulate.com,1); //Redirects to blogulate.com in 1 second.
?>
Eg Usage :
js_redirect(http://google.com,5); //Redirects to Google after 5 seconds.

Spellify automatically checks for spelling errors on user entered text in input text fields. Spellify is powered by the Google™ spell checker. You can see a demo at te homepage and also download the latest version there. Spellify not only works for text fields, but also on text areas.
Open Flash Chart lets you make great chart/pie representations from you data for a great looking output. The data file is either a text file, or a .php, Perl, Python, Java (or another flavour of dynamic) page.


Open Flash Chart, is open source. It is free to use and you get the source code to fiddle with!
# Charts Available
* Data Lines
* Bar Chart
* Bar Chart 2
* 3D Bar Chart
* Glass Bar Chart
* Fade Bar Chart
* Sketch Bars
* Area Charts
* Bars + Lines
* Pie Chart
* Pie Chart Links
* Scatter Chart
* High Low Close
* Candle
# Other Features :
* Chart Title
* Line and Key
* Tool tip
* Background Style
* Background Image
* Inner Background Style
* Null data values
* X Offset
* Bar Links
* Format Numbers
* Do more with less
* Pareto chart
# Helper classes * Java
* Perl
* Python
* Ruby and Rails
* PHP
* .NET
Download Open Flash Chart Open Flash Chart Latest : Version 1.9.6 (550 Kb)
/* PHP Performance Benchmark Script Copyright 2003 : PHP Consulting There are two settings: First, set $file to be the server and page that you want to benchmark. Secondly, set $iter to be the number of times you want it loaded. */
error_reporting(E_ALL ^ E_NOTICE); //For disabling non fatal error outputs
$file = "http://127.0.0.1/Joomla/index.php"; //Location to file
$iter = 5; //No of times to check
function getmtime()
{
$a = explode (' ',microtime());
return(double) $a[0] + $a[1];
}
for ($i = 0; $i < $iter; $i++)
{
$start = getmtime();
file ($file);
$loadtime += getmtime() - $start ;
$intertime = getmtime() - $start ;
echo $intertime . "<br>" ;
$avgload = $loadtime / $iter;
}
echo "<p><b>Average" . $avgload . "</b>" ;
?>
<?php
function filename_safe($filename) {
$temp = $filename;
// Lower case
$temp = strtolower($temp);
// Replace spaces with a ’_’
$temp = str_replace(“ ”, “_”, $temp);
// Loop through string
$result = ”;
for ($i=0; $i<strlen($temp); $i++) {
if (preg_match(‘([0-9]|[a-z]|_)’, $temp[$i])) {
$result = $result . $temp[$i];
}
}
// Return filename
return $result;
}
?>
