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
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
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
Share on other sites

My version :)

[code]<?php
function update_ordnum($ordnum){
if(ereg("[0-9]{1}00[0-9]{4}",$ordnum)){return $ordnum;}
else{
$arr=array();
$arr[0]=$ordnum{0};
$arr[1]="00";
$arr[2]=substr($ordnum, 1);
$ordnum=implode("",$arr);
return $ordnum;
}
}
?>[/code]


Orio :)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.