View Single Post
Old 09-07-2007, 10:36 AM   #6 (permalink)
Salathe
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,239
Thanks: 3
Salathe is on a distinguished road
Default

Quote:
Originally Posted by Wildhoney View Post
PHP Code:
function getPrefix($szPointer)
{
    
$aVariable str_split($szPointer);
    
$szPrefix '';
    
    foreach(
$aVariable as $szVariable)
    {
        
$szOrd ord($szVariable);
        
        if(
$szOrd >= 65 && $szOrd <= 90)
        {
            break;
        }
        
        
$szPrefix .= $szVariable;
    }
    
    return 
$szPrefix;

I'm just wondering why you went the route of split/foreach when a simple RegEx would be more readable (personally, I find it easier to glance at a pattern than work through a sequence of loops) and probably quicker? Also, in the case of 'pointers' without an uppercase character (e.g. random) the full string would be returned -- I'd have thought that in that sort of case, there'd logically be no prefix.
Salathe is offline  
Reply With Quote