Jump to content

spliting a string of numbers


pctechtime

Recommended Posts

I am trying to input a string of numbers and have it go into 4 different fields of a database. See below
Any help would be great.


data to input 0215446912345678

scan_field          // this is the field the above number would go into and also needs to be broken up into the fields below
item_number      // this is the field the first 6 numbers would go into
grade                // this is the field the next 2 numbers would go into
serial_number    // this is the field the last numbers would go into (the last set of numbers can be 1 to many in length
Link to comment
https://forums.phpfreaks.com/topic/33899-spliting-a-string-of-numbers/
Share on other sites

This:
[code]<?php

$input = "0215446912345678";

$scan_field = $input;
$item_number = substr($input, 0, 6);
$grade = substr($input, 6, 2);
$serial_number = substr($input, 8);

echo "Scan Field: " . $scan_field . "<br>";
echo "Item number: " . $item_number . "<br>";
echo "Grade: " . $grade . "<br>";
echo "Serial number: " . $serial_number . "<br>";

?>[/code]

Produces this:
[code]Scan Field: 0215446912345678
Item number: 021544
Grade: 69
Serial number: 12345678[code][/code][/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.