简体   繁体   中英

php barcode scan manipulate data web form

Thank you for any help in steering me in the right direction. I have a php form that has been running since 2014 inputting data into a mysql database. Now i would like to scan a barcode into one field, but i only need certain data from this barcode scan. When I scan it i get a long string of data.

example of data i get when i scan the barcode

<Bearing>
   <COMPANYcODE>c480</COMPANYcODE>
   <IDnUMBER>l412040193</idNumber>
   <C203>PRBK</C203>
   <C204>2020-05-20T15:33:51</C204>
   <C205>428946</C205>
   <C206>13</C206>
   <C207>11</C207>
   <C208>6.5</C208>
   <C209>9.0</C209>
   <C210>27</C210>
   <C21l>R</C2ll>
   <C213>8AMS00OS</C213>
   <C214>SOEX0003</C214>
   <C215>AARX0002</C215>
   <C216>AARX0001</C216>
   <C217>AARX0001</C217>
</Bearing>

On my input field I only want the numbers between the C205 c206 and c207 above all on one line no spaces.

Im not sure how to do this. Basically when i scan the barcode i would like this one input field to only show 4289461311 using the example above. Any help would be greatly appreciated. Thanks
I can send my code example if needed. But its just a simple input form. Also if its easier to change the data once it gets added to mysql database, any help on doing that would be appreciated. Thanks

Here is a way to do it:

$data = "<Bearing><COMPANYcODE>c480</COMPANYcODE><IDnUMBER>l412040193</idNumber><C203>PRBK</C203><C204>2020-05-20T15:33:51</C204><C205>428946</C205><C206>13</C206><C207>11</C207><C208>6.5</C208><C209>9.0</C209><C210>27</C210><C21l>R</C2ll><C213>8AMS00OS</C213><C214>SOEX0003</C214><C215>AARX0002</C215><C216>AARX0001</C216><C217>AARX0001</C217></Bearing>";

if(!preg_match_all('/<(C205|C206|C207)>(.+?)<\/\1>/', $data, $out)) {
    echo "No Data Found";
} else {
    $myvalues = join('', $out[2]);
    echo $myvalues;
}

// output:
// 4289461311

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM