-1

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

Weadom
  • 21
  • 1
  • 8
  • 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
  • 1
    possible duplicate of [simple PHP string replace?](http://stackoverflow.com/questions/5644947/simple-php-string-replace) – Chad Nouis Sep 15 '15 at 15:34

2 Answers2

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
?>
0

Use substr:

$str = "C1N96";    
$str = substr($str, 3);
littleibex
  • 1,705
  • 2
  • 14
  • 35