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.
Asked
Active
Viewed 236 times
1
-
2`c` or `php`? Make a choice. – devnull Feb 15 '14 at 09:58
-
Any solution attempts ? Have you tried anything ? – BlitZ Feb 15 '14 at 09:58
-
`preg_replace('/\D/', '', $str); // 495321`. For a C-based solution, take a look at [this answer](http://stackoverflow.com/a/13399677/1438393). – Amal Murali Feb 15 '14 at 09:59
3 Answers
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
-
3This is a rephrase of [this answer](http://stackoverflow.com/a/11243531/). – Amal Murali Feb 15 '14 at 10:10
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