Sphinx search

Sphinx Search Sphinx is a free standalone full-text search engine. It is fast, efficient, and easily integrates with SQL databases and programming major programming languages. It is ideal for use with MySQL, PostgreSQL, PHP, Python, Perl and Ruby. Although Sphinx works well with Java but Lucene is better option for Java.

Following is a summary of features (copied from http://www.sphinxsearch.com)

Converting string to date in PHP

Converting strings to dates in PHP requires the use of two functions. strtotime function converts the string to an epoch timestamp. date function converts the timestamp to the desirable date format.

<?php
   $string = "Nov 11, 2011";
   $timestamp = strtotime($string);
   $date = date("Y-m-d", $timestamp);
   print $timestamp . "<br>" . $date;
?>

output

PHP Manipulating XML with SimpleXML

SimpleXML is a SAX XML parser. It represents an XML document as a hierarchical set of objects and properties where each element is an object and each attribute is an object property.

Access an XML element using SimpleXML

<?xml version='1.0'?>
<hotels>
   <hotel stars="5">
       <name>President Wilson</name>
       <city>Geneva</city>
       <country>Switzerland</country>
   </hotel>
</hotels>

Save this file as hotel.xml

PHP Benchmark Results

Benchmarking is the process of evaluating existing processes and identifying best practices. For example, there are three ways to loop through an array, we would test each method and identify the best performing method. In terms of code, this very often means identifying methods that would be least expensive in terms of CPU time and memory consumption.

Following is a simple benchmark script. It compares while loop with for loop.

Pages