Jump to content


Photo

matching order number


  • Please log in to reply
4 replies to this topic

#1 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 24 July 2006 - 05:32 PM

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


#2 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 24 July 2006 - 06:25 PM

<?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);
}
?>


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.
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#3 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 24 July 2006 - 06:26 PM

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


?>
EDIT: tested. you don't even need to worry about length. 8 digit codes won't match the regex and won't get replaced.
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#4 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 24 July 2006 - 06:55 PM

My version :)

<?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;
}
}
?>


Orio :)
Think you're smarty?

(Gone until 20 to November)

#5 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 24 July 2006 - 07:06 PM

if all the old order numbers were 6 digits, just check the length.

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

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

Ray





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users