Jump to content

matching order number


AV1611

Recommended Posts

Hi.  I have a script that I send a $_post from a form to.  we just upgraded our server, now our orders have changed.  the old order number looked like this:  514678
our new order numbers look like this:  50014678.

what they did was take the first number and add 2 0's...

so, for my script to work, I need to do the following:

if ($_POST['ORDNUM']==[i don't know what do do here])
{use the number}
else
{do something to convert the 6 digit number to the 8 digit number}

need the clause to recognize if it is in the 8 digit format, then make a $var out of it, but if it is 6 digit format, add the two 0's after the first number then make the $var out of it.

the first number is not always a 5

I dont' know if it's preg replace or what???

Help? Suggestion for the function I need? Anything?

Thx
Link to comment
https://forums.phpfreaks.com/topic/15516-matching-order-number/
Share on other sites

[code]<?php
$ordernum=514678;
$array=explode('',$ordernum);
if (count($array) == 6) {
$i=1;
foreach($array as $digit) {
  if ($i == 1) {
  $var=$digit.'00';
  } else {
    $var=$var.$digit;
  $i++;
  }
}
}
if (count($array) == 8) {
$var=implode($array);
}
?>[/code]


That *would* work if you can get someone to tell u how to explode by charactor.. atm explode has to explode by somthing so not sur ehow to.
Link to comment
https://forums.phpfreaks.com/topic/15516-matching-order-number/#findComment-63040
Share on other sites

with regex
[code]<?php
echo preg_replace('/^(\d)(\d{5})$/','${1}00$2',514678);    //50014678
echo preg_replace('/^(\d)(\d{5})$/','${1}00$2',50014678);  //50014678


?>[/code]EDIT: tested. you don't even need to worry about length. 8 digit codes won't match the regex and won't get replaced.
Link to comment
https://forums.phpfreaks.com/topic/15516-matching-order-number/#findComment-63041
Share on other sites

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.