Reply to Re: is_blank()?

Your name:

Reply:


Posted by Mike P2 on 05/11/07 21:34

I don't understand what's wrong with:

if( trim( $variable ) == '' )

I just benchmarked it, it's faster than the regex methods.

By the way, I think the best regex to search with would be '#\S#',
because that would indicate that the string contains at least one non-
whitespace character anywhere in the string. That is the pattern I
used in the benchmarking.

<?php //quick benchmark test
$t1 = 'asdfasdf ';
$t2 = ' ';
$i = 0;
$tTrim = microtime( true );
for( ; $i < 10000; ++$i )
{
trim( $t1 ) == '';
trim( $t2 ) == '';
}
$tTrim = microtime( true ) - $tTrim;
$i = 0;
$tRegEx = microtime( true );
for( ; $i < 10000; ++$i )
{
preg_match( '#\S#', $t1 );
preg_match( '#\S#', $t2 );
}
$tRegEx = microtime( true ) - $tRegEx;
printf( "trim: %f<br />regex: %f", $tTrim, $tRegEx );
?>

Besides, although I usually place little value in this, I think it's
easier to read ( trim( $var ) == '' ) than to interpret a regex
pattern.

-Mike PII

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация