Welcome to the Browser-Base Game Zone forums!
$len=strlen($tmp); for($n=0;$n<$len;$n++) if(ord($tmp[$n])>32) {$nonblank=1; break;} if(!$nonblank) {$ok=0; error("Enter something.");}
if (trim($tmp) == '') { error(...);}
$t=explode(' ',$text);$count=count($t);for($n=0;$n<$count;$n++) {if(strlen($t[$n])>80) {$ok=0; error("Maximum word length is 80 characters");}}
A question. When we have an overly complex build in function that does a lot of processing we don't need (but compiled to native machine code) or a small and simple code in PHP that does only what it needs to (but processed by slow interpreter), which one should we choose as a rule of thumb? What are your thoughts on this?
Another question (detect max word size):How to make it faster (I can not use wordwrap because it 'fix' the string while I want to 'validate" the string)?Code: [Select]$t=explode(' ',$text);$count=count($t);for($n=0;$n<$count;$n++) {if(strlen($t[$n])>80) {$ok=0; error("Maximum word length is 80 characters");}}
if (preg_match('#[^\s]{81,}#', $text)) error('Maximum word length is 80 characters');
if (max(array_map('strlen', explode(' ', $text))) > 80) error('Maximum word length is 80 characters');