sager29 Posted January 2, 2008 Share Posted January 2, 2008 Hi everyone, I’ve created a code ($item1) What I’m trying to do is read certain numbers of the code to tell my site what kind of membership to create. For instance 12****** is the length of service **00**** is account type, and so on My code doesn’t work. Any suggestions would be greatly appreciated $item1 = 12001102; if ( $item1 == 12****** ) { echo "you have 12 months"; } else { echo "don’t do anything"; } Quote Link to comment https://forums.phpfreaks.com/topic/84081-solved-product-code-interpreting/ Share on other sites More sharing options...
adam291086 Posted January 2, 2008 Share Posted January 2, 2008 You will need away to break up the number. Therefore when you create the number seperate each bit on infor with a "-" then you could do something like this $pizza = "12-00-00-00"; $pieces = explode("-", $pizza); echo $pieces[0]; // 12 echo $pieces[1]; // 00 look at explode in the manual Quote Link to comment https://forums.phpfreaks.com/topic/84081-solved-product-code-interpreting/#findComment-427978 Share on other sites More sharing options...
GingerRobot Posted January 2, 2008 Share Posted January 2, 2008 You dont have to separate by slashes/dashes. You could either use the substr() funcion , or rebuild the new string by accessing the characters individually: <?php $num = '12001102'; $length = $num[0].$num[1];// $account_type = substr($num,2,2); echo $length.'<br />';; echo $account_type; ?> That said, separating by shashes would probably be better - what happens if one of thse suddently needs to be 3 digits long. If you separate by shashes, it wouldn't be a problem. Finally, if this data is coming from a database table, you'd be better off storing each piece of information individually. What happens when you suddenly want to see all the items where the account type is 00? If could be done with the way you're storing information at present, but it would be easier if you stored each piece separately. Quote Link to comment https://forums.phpfreaks.com/topic/84081-solved-product-code-interpreting/#findComment-427982 Share on other sites More sharing options...
sager29 Posted January 2, 2008 Author Share Posted January 2, 2008 thanks, I'll give that a try Quote Link to comment https://forums.phpfreaks.com/topic/84081-solved-product-code-interpreting/#findComment-427985 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.