hypercoffeedude Posted May 7, 2010 Share Posted May 7, 2010 Hello everyone! I maintain a e-commerce site for someone, and I would like to be able to decode a SKU number. The SKU is created in a way that it can decribe a products quality, year, etc... so a SKU like: 252AER2 would mean: Part No: 252 Compatable With Model: 555 (a) Power Source: 12V (e) etc... The SKU is displayed on each of the product pages. Is there a way to parse the SKU at load and decode it into a description? I want to be able to serve up a description purely based on the SKU alone. A "plug-n-play" solution if you will. Quote Link to comment https://forums.phpfreaks.com/topic/200987-need-to-decode-a-sku-with-php/ Share on other sites More sharing options...
salathe Posted May 7, 2010 Share Posted May 7, 2010 So you just want to break the string into pieces at the relevant positions; or would it be more complex (are pieces optional, how do you get 555 from A, etc.)? Quote Link to comment https://forums.phpfreaks.com/topic/200987-need-to-decode-a-sku-with-php/#findComment-1054502 Share on other sites More sharing options...
hypercoffeedude Posted May 7, 2010 Author Share Posted May 7, 2010 There will be a definite amount of chunks. (252) (A) (E) ® (2) (A) will always mean a specific value such as "555" with the words "Model No." placed behind it. (A) and the others will always be a specific value, the letters will change depending on attributes so (A) = "555" always. (B) may always represent "444". (2) Represents a level of quality so 2 = "Quality: Good Condition/Only Light Scratches" (1) would represent "Quality: Like new condition / No scratches" I want to input the SKU on my product, and have a script fill the description for me based off the SKU. The script will include all possible values for each section of the SKU. Currently there are 5 sections. The script will be plugged into the description box of every product without being modified. This is why it will need to grab the SKU off of the page. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/200987-need-to-decode-a-sku-with-php/#findComment-1054505 Share on other sites More sharing options...
teamatomic Posted May 7, 2010 Share Posted May 7, 2010 Use substr to break the string into parts then use the parts to plug into arrays to get what you want. ie. condition(1=>'excellent condition/no scratches',2=>'Good Condition/Only Light Scratches'3=>'fair condition/moderate scratching'4=>'poor condition/heavy scratching'5=>'usless condition/looks like cat scratch fever') echo "$condition[$part_condition]"; or use the $str_condition to pull from a DB. HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/200987-need-to-decode-a-sku-with-php/#findComment-1054649 Share on other sites More sharing options...
hypercoffeedude Posted May 8, 2010 Author Share Posted May 8, 2010 I will need to parse the page as well in order to grab the SKU as a string. How could I do this? The HTML of the loaded page is in a DIV <div class="product-info model">SKU: 252AER2</div> Quote Link to comment https://forums.phpfreaks.com/topic/200987-need-to-decode-a-sku-with-php/#findComment-1054970 Share on other sites More sharing options...
xeross Posted May 8, 2010 Share Posted May 8, 2010 I will need to parse the page as well in order to grab the SKU as a string. How could I do this? The HTML of the loaded page is in a DIV <div class="product-info model">SKU: 252AER2</div> You can use a regular expression to extract it. Quote Link to comment https://forums.phpfreaks.com/topic/200987-need-to-decode-a-sku-with-php/#findComment-1054991 Share on other sites More sharing options...
hypercoffeedude Posted May 10, 2010 Author Share Posted May 10, 2010 You can use a regular expression to extract it. Well, as easy as it sounds, I don't know how to write a RegEx that would take my text and push it into a varable. I honestly don't know much at all about PHP in a programming sense. My programming levels are good, just not with PHP. This PHP script will be placed inside the "body" of a Drupal type page. Drupal has ways of using PHP code in a description box. Quote Link to comment https://forums.phpfreaks.com/topic/200987-need-to-decode-a-sku-with-php/#findComment-1055722 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.