1

Hello I have WR4G9T5HTJ3w2RFG1 string which contains alphabatic and numeric letters so I want get the numbers from this string like 123459. So please help me to solve this.

BlitZ
  • 11,836
  • 3
  • 49
  • 64
craig
  • 367
  • 4
  • 14

3 Answers3

1

try this

PHP

echo getNumbersFromString('WR4G9T5HTJ3w2RFG1');
function getNumbersFromString ($str) {
        preg_match_all('/\d+/', $str, $matches);
        return implode("",$matches[0]);
    }

i have put some part of code from here

my intension was not to copy the answer i just used and modify the answer as per the question requirement.

Community
  • 1
  • 1
Satish Sharma
  • 9,475
  • 6
  • 27
  • 51
0
$str= 'salom34554dfgfd';
        $array[]='salom34554dfgfd';
        for($i=1; $i<strlen($str); $i++){
            if(is_numeric($array[0][$i])){
                echo $array[0][$i];
            }
        }

i think u mean this

0

result code :

$result = preg_replace('/[^a-zA-Z]/', '', $your_string);

or

$result = preg_replace('/\D/', '', $your_string);
evergreen
  • 6,981
  • 2
  • 14
  • 25