Jump to content

Archived

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

AV1611

matching order number

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

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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 :)

Share this post


Link to post
Share on other sites
if all the old order numbers were 6 digits, just check the length.

[code]if(strlen($_POST['ORDNUM']) == 6){
// convert script here
} else {

$ordnum = $_POST['ORDNUM'];
}[/code]

Ray

Share this post


Link to post
Share on other sites

×

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.