-2

i have this code tath cames form and RFID card ccffff10320d011899540002692a000002692ab7

i have a php system i need to show only the 14,15,16,17,18,19 digit (189954) is there a way of doing it? the 6 digit number al already store in my database so what the system does is if the number match is will give you asistance.

  • You can use `str_split` to split the string into an array, then use a `for` loop to start at 14 and end at 19, concatenating an output string based on the array with index 14, 15, 16, etc. – Jacob Mulquin Sep 26 '21 at 06:52
  • What have you already tried to do? Please, follow this to create a minimal example to help reproduce the problem https://stackoverflow.com/help/minimal-reproducible-example – oniramarf Oct 04 '21 at 08:48

2 Answers2

1

Use substr()


$rfid = "ccffff10320d011899540002692a000002692ab7";

$a = substr($rfid, 14, 6); //189954

Demo: https://3v4l.org/nEjSs

0

You can get the value which you want, using the pattern I wrote for you.

If you want to get 6 digits:

preg_match('/([0-9a-z]{14})([0-9]{6})([0-9a-z]{20})/', $input_line, $output_array);

Output:

array(4
0   =>  ccffff10320d011899540002692a000002692ab7
1   =>  ccffff10320d01
2   =>  189954
3   =>  0002692a000002692ab7
)
Şahin Ersever
  • 326
  • 1
  • 8
  • A regex seems needlessly complicated for this simple requirement. – Tangentially Perpendicular Sep 26 '21 at 09:47
  • It can also check the correctness of the entered number. `ccffff10320d01<77>99540002692a000002692ab7` think about this number it should be start with 14,15,16,17,18,19 – Şahin Ersever Sep 26 '21 at 09:54
  • The question isn't asking for any validation. I think you've read more into it than is there. – Tangentially Perpendicular Sep 26 '21 at 09:57
  • I think you misunderstood the requirement. The substring OP is looking for should not start with the numbers 14, 15, 16, 17, 18 or 19, but instead OP is looking for the characters at positions 14-19. – rickdenhaan Sep 26 '21 at 09:58
  • God! I misunderstood the requirement :/ sorry. I change the answer. Thank you – Şahin Ersever Sep 26 '21 at 10:00
  • My answer can be a good alternative :) – Şahin Ersever Sep 26 '21 at 10:07
  • Thanks for your help, let me brake this: wen i ready the card it give me this code: ccffff10320d011899540002692a000002692ab7 I only need the digit 14 to the 19 in this case (189954) if i scan the rest of my cards the first 14 digits are the same, so i need to show only 14,15,16,17,18,19, because i have an input were it will let you in if those 6 digits are the same in my data base. hope i can explain better – Esteban Gonzalez Sep 26 '21 at 15:35