AV1611 Posted July 24, 2006 Share Posted July 24, 2006 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: 514678our 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 5I 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 More sharing options...
shocker-z Posted July 24, 2006 Share Posted July 24, 2006 [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 More sharing options...
ryanlwh Posted July 24, 2006 Share Posted July 24, 2006 with regex[code]<?phpecho preg_replace('/^(\d)(\d{5})$/','${1}00$2',514678); //50014678echo 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 More sharing options...
Orio Posted July 24, 2006 Share Posted July 24, 2006 My version :)[code]<?phpfunction 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 https://forums.phpfreaks.com/topic/15516-matching-order-number/#findComment-63071 Share on other sites More sharing options...
craygo Posted July 24, 2006 Share Posted July 24, 2006 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 Link to comment https://forums.phpfreaks.com/topic/15516-matching-order-number/#findComment-63082 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.