I need code for get number after caracters in one string. For exmple i have value C1N96 and i whant only 96. Others example: if I have string C1N99 must be displayed 99 if I have string C1N1022 must be displayed 1022 I need something that remove "C1N" from result displayed. thanks
Asked
Active
Viewed 838 times
-1
-
possible duplicate of [Get first n characters of a string](http://stackoverflow.com/questions/3161816/get-first-n-characters-of-a-string) – Rick Smith Sep 15 '15 at 15:25
-
This is pretty much the same question as [this](http://stackoverflow.com/questions/3161816/get-first-n-characters-of-a-string) only you want the last N characters instead of the first. – Rick Smith Sep 15 '15 at 15:26
-
1possible duplicate of [simple PHP string replace?](http://stackoverflow.com/questions/5644947/simple-php-string-replace) – Chad Nouis Sep 15 '15 at 15:34
2 Answers
3
If it is only C1N
, then you can use like this:
$main = "C1N983";
$number = str_replace('C1N', '', $main); // 983
or a more greater way use a regular expression like this:
<?php
$text = "C1N384";
$regex = "/C1N([0-9]+)/";
preg_match($regex, $text, $matches);
echo $matches[1]; //384
?>

Amir Hossein Baghernezad
- 3,616
- 27
- 28