GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   php question ... (https://gfy.com/showthread.php?t=444595)

PSD 03-15-2005 11:09 PM

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?

etech 03-16-2005 01:13 AM

PHP Code:

$variable strlen("TestString"); 

strlen will return the number of characters in the string

broke 03-16-2005 01:40 AM

PHP Code:


<?php

  $str 
"00jkjdj0";
  
  
$char_count 0;
  
$num_count 0;
  
  
$u_bound strlen$str ) - 1;
  
  for( 
$i $i <= $u_bound $i++ ) {
  
    if( 
is_numeric$str$i } ) ) { $char_count++; } else { $num_count++; }
  
  }
  
  echo 
$char_count;
  echo 
$num_count;
  
?>


broke 03-16-2005 01:51 AM

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 :winkwink: ) ...

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 $i <= $u_bound $i++ ) {
  
    if( 
is_numeric$str$i } ) ) { $num_count++; } else { $char_count++; }
  
  }
  
  echo 
$char_count;
  echo 
$num_count


SmokeyTheBear 03-16-2005 01:54 AM

Its cheaper to outsource the job to eager young pakistani counting experts


All times are GMT -7. The time now is 05:18 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123