php question ...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PSD
    PornSiteDomains.com
    • Oct 2002
    • 1265

    #1

    php question ...

    Anyone know of a function that will count only the number of letters in a string and only the number of digits in a string?
    PornSiteDomains.com
  • etech
    Confirmed User
    • Feb 2004
    • 1148

    #2
    PHP Code:
    $variable = strlen("TestString"); 
    
    strlen will return the number of characters in the string

    Comment

    • broke
      Confirmed User
      • Aug 2003
      • 4501

      #3
      PHP Code:
      
      <?php
      
        $str = "00jkjdj0";
        
        $char_count = 0;
        $num_count = 0;
        
        $u_bound = strlen( $str ) - 1;
        
        for( $i = 0 ; $i <= $u_bound ; $i++ ) {
        
          if( is_numeric( $str{ $i } ) ) { $char_count++; } else { $num_count++; }
        
        }
        
        echo $char_count;
        echo $num_count;
        
      ?>
      Perfect Gonzo

      Comment

      • broke
        Confirmed User
        • Aug 2003
        • 4501

        #4
        Sorry. I mixed up my variabless in the following line (unless you want to use $char_count as the number count variable and $num_count as the character count variable ) ...

        PHP Code:
        if( is_numeric( $str{ $i } ) ) { $char_count++; } else { $num_count++; } 
        
        It should read...

        PHP Code:
        if( is_numeric( $str{ $i } ) ) { $num_count++; } else { $char_count++; } 
        


        Full code:

        PHP Code:
        
          $str = "00jkjdj0";
          
          $char_count = 0;
          $num_count = 0;
          
          $u_bound = strlen( $str ) - 1;
          
          for( $i = 0 ; $i <= $u_bound ; $i++ ) {
          
            if( is_numeric( $str{ $i } ) ) { $num_count++; } else { $char_count++; }
          
          }
          
          echo $char_count;
          echo $num_count; 
        
        Perfect Gonzo

        Comment

        • SmokeyTheBear
          ►SouthOfHeaven
          • Jun 2004
          • 28609

          #5
          Its cheaper to outsource the job to eager young pakistani counting experts
          hatisblack at yahoo.com

          Comment

          Working...