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
  • 12,038
  • 3
  • 49
  • 68
craig
  • 377
  • 4
  • 15

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,547
  • 6
  • 29
  • 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

Sherali Obidov
  • 119
  • 1
  • 2
  • 9
0

result code :

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

or

$result = preg_replace('/\D/', '', $your_string);
evergreen
  • 7,771
  • 2
  • 17
  • 25