preg_replace trim vs. trim

Regular expressions incur a significant amount of overhead. If there is a suitable PHP function, it should always be used before coding a regular expression.

<?php

$sWord = '   TestString    ';

/* Time preg_replace trim double quotes */
$fStartPreg=microtime(true);
$sPreg=preg_replace("/^\s+|\s+$/", "", $sWord);
$fEndPreg=microtime(true);

/* Time preg_replace trim single quotes */
$fStartPregSng=microtime(true);
$sPreg=preg_replace('/^\s+|\s+$/', '', $sWord);
$fEndPregSng=microtime(true);

/* Time trim */
$fStartTrim=microtime(true);
$sTrim=trim($sWord);
$fEndTrim=microtime(true);

/* Calculate elapsed times */
$fPregElapsed=$fEndPreg-$fStartPreg;
$fPregElapsedSng=$fEndPregSng-$fStartPregSng;
$fTrimElapsed=$fEndTrim-$fStartTrim;

/* Display output */
echo '<html>';
echo '<pre>';
echo htmlentities(file_get_contents('timetest.php'));
echo "\n\n";
echo '$sWord: -'.$sWord."-\n";
echo '$sPreg: -'.$sPreg."-\n";
echo '$sTrim: -'.$sTrim."-\n";
printf("preg_replace:\t%f<br />",$fPregElapsed);
printf("preg_replace:\t%f (single quotes)<br />",$fPregElapsedSng);
printf("trim:\t\t%f<br />",$fTrimElapsed);
printf("difference:\t%f<br />",$fPregElapsed-$fTrimElapsed);
echo '</pre>';
echo '</html>';

?>

$sWord: - TestString -
$sPreg: -TestString-
$sTrim: -TestString-
preg_replace: 0.000114
preg_replace: 0.000012 (single quotes)
trim: 0.000008
difference: 0.000106

This page also demonstrates the impact of single quotes vs. double quotes.

Technical Terminology Divide

Web sites are becoming exponentially more complex and more expensive, and the terms that describe the technology are becoming equally sophisticated and diverse.

At the same time, people purchasing web sites are seeking advanced features, and may be confused by the plethora of terms.

Web development firms should describe the services such that a potential client can understand the services offered, without concerning themselves with the underlying technology.

Equivalent terms

  • Content Management System (CMS) / Blog - means the client can edit the content on the site without special technical skills or tools
  • ecommerce - Web based sale of goods
  • Open Source Applications - Commercial code that can be customized or extended
  • Validator - Used to ensure the web site code complies with standards. Indicates an attempt to develop quality code

In addition, they should highlight sites that reflect their strongest market share.

Specifications and Requirements are Vital

In a rapid development environment, specifications and requirements are vital. There is no time to build a solution that is not acceptable.

If there isn’t an adequate requirements defininition, a general approach should be defined, and routine, quick, checks should be performed to ensure the progress is in line with expectations.

Skin an Old Site with New Colors

Many times, the existing HTML site cannot be abandoned quickly, but updating the colors can help reinvigorate the pages.

If the code has alot of inline colors and styles, automating the recoloring makes it possible to preserve the existing investment, but still apply new colors.

Rapidly changing the colors of X-Cart's skin1.css

robots.design works extremely well with X-Cart’s skin1.css. There are many colors and they map nicely with most images. There is a demo of a static image of an X-Cart home page at http://wirehopper.com/x-cart. The colors are derived from the same image used to color this blog.

Sincere thanks to X-Cart for allowing the use of the files to support this demonstration.