[thelist] PHP show first 10 words of MySQL field

Kelly Hallman khallman at wrack.org
Thu Aug 28 15:19:46 CDT 2003

On Thu, 28 Aug 2003, SBeam wrote:
> On Thursday 28 August 2003 05:28 am, Kelly Hallman wrote:
> > $x = "The quick brown fox jumps over the lazy ".$test.".";
> >    +  concatenation double quotes                     0.3742000000
> dont forget sprintf() - I get similar results as your last example using
> $x = sprintf('The quick brown fox jumps over the lazy %s', $test);

Perhaps your machine is twice as fast as mine, because when I added a 
sprintf loop I got a time that was a bit more than double the 
concatenation loop time above:

$x = sprintf("The quick brown fox jumps over the lazy %s.",$test);
   +  sprintf string substitution                     0.8422000000

Still beats an interpolated string, and it does provide some advantages as 
you demonstrated. So, again it's a case where it's best to learn and 
understand all the available options, and choose the one that best suits 
your preferences or particular circumstance.

The performance aspect is interesting to note, but I wouldn't always pick 
the fastest way simply for that reason. Issues of code readability, 
maintenance and style all play in here, and in most scenarios the 
performance differences probably wouldn't be significant.

The original point was a good one though, there is no cause to use "$var", 
when you could simply use $var and avoid the interpolation overhead.

Kelly Hallman

More information about the thelist mailing list