java - Extract numeric value from an alphanumeric string without using any predefined function -


i have variable

$string  = "(123) 011 - 34343678"; 

and want 12301134343678 output in integer data type. how can without using predefined function in php or in other programming language.

well it's not nicest solution, work you:

here loop through characters , check if still same when cast them integer , string. if yes number otherwise not.

<?php      function own_strlen($str) {         $count = 0;         while(@$str[$count] != "")             $count++;         return $count;     }      function removenonnumericalcharacters($str) {         $result = "";          for($count = 0; $count < own_strlen($str); $count++) {             $character = $str[$count];             if((string)(int)$str[$count] === $character)                 $result .= $str[$count];         }          return $result;      }      $string  = "(123) 011 - 34343678";     echo removenonnumericalcharacters($string);  ?> 

output:

12301134343678 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -