Page 1 of 1
[HELP ME] create product code using PHP??
Posted: Fri Aug 20, 2010 12:03 pm
by drawan
I am from Indonesia
help me, how to create logic of product code in accordance with the product name using script PHP?
example :
input product name : Toshiba Dynabook SS2000 Japan Product Notebook
then saved, product code become TDSJPN001
so that each combination of initial letters + three-digit number
Thanks.
Re: [HELP ME] create product code using PHP??
Posted: Fri Aug 20, 2010 12:25 pm
by AbraCadaver
You'll have to work out how you determine what the number is. If you already have the same product code that ends in 001, then you'll need to increment it, but I don't know where you have stored these:
Code: Select all
$name = 'Toshiba Dynabook SS2000 Japan Product Notebook';
$words = str_word_count($name, 1);
$code = '';
foreach($words as $word) {
$code .= $word[0];
}
$code .= sprintf('%03s', 1);
Re: [HELP ME] create product code using PHP??
Posted: Fri Aug 20, 2010 2:16 pm
by jaiswarvipin
Hi,
adding to above you can use the following as well
Code: Select all
$name = 'Toshiba Dynabook SS2000 Japan Product Notebook';
$nameArray = explode(" ",$name);
$name = "";
for($intCount = 0; $intCount < sizeof($nameArray) ; $intCount++)
$name . = substr($nameArray,0,1);
above code only give you first Intilai of the String then not it's depending on your requriement .i.e. If you Number in sequeance then yo uneed to get any how the previuos number and if not then you can generate the random number of three degit usinf rand(3);
Re: [HELP ME] create product code using PHP??
Posted: Fri Aug 20, 2010 4:08 pm
by drawan
@jaiswarvipin and @AbraCadaver
I apologize because I'm less familiar with PHP
so please guide?