killah Posted February 3, 2009 Share Posted February 3, 2009 Is there any php function that i can use to check if a number is in a string? I have this code $errno = array($soc['oUPGRADES']); if( in_array($soc['upID'], $errno[0]) ) { echo ' <option value="null">'.$soc['upNAME'].' (Already Bought)</option>'; } but it does not seem to work I am trying to do something like this in other word's. if( 1 is in (9,7,1, ) { //already bought } Any help would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/143553-solved-php-function/ Share on other sites More sharing options...
DeanWhitehouse Posted February 3, 2009 Share Posted February 3, 2009 You can use a regex to check for numbers Quote Link to comment https://forums.phpfreaks.com/topic/143553-solved-php-function/#findComment-753140 Share on other sites More sharing options...
phpSensei Posted February 3, 2009 Share Posted February 3, 2009 edit: nvm already posted Quote Link to comment https://forums.phpfreaks.com/topic/143553-solved-php-function/#findComment-753141 Share on other sites More sharing options...
killah Posted February 3, 2009 Author Share Posted February 3, 2009 Problem is $soc['oUPGRADES'] is always updated with more number's. And each time a number is added it put's it like this $OLD = '98,76,3,4'; $new_n = '1'; $NEW = $OLD.','.$new_n; $NEW = '98,76,3,4,1'; Quote Link to comment https://forums.phpfreaks.com/topic/143553-solved-php-function/#findComment-753149 Share on other sites More sharing options...
trq Posted February 3, 2009 Share Posted February 3, 2009 Why is that the problem? Quote Link to comment https://forums.phpfreaks.com/topic/143553-solved-php-function/#findComment-753155 Share on other sites More sharing options...
gevans Posted February 3, 2009 Share Posted February 3, 2009 You can use a regex to check for numbers That would make it a lot more draining process than necessary when you could use strpos() <?php $your_var = '9,7,1,8'; if(strpos($your_var,1) !== FALSE) { //already bought } Quote Link to comment https://forums.phpfreaks.com/topic/143553-solved-php-function/#findComment-753157 Share on other sites More sharing options...
DeanWhitehouse Posted February 3, 2009 Share Posted February 3, 2009 And then what if they want to check for a whole range of different numbers, they would need an array from 0 to 9, when they could just something like *(0-9) (or whtever it is) Quote Link to comment https://forums.phpfreaks.com/topic/143553-solved-php-function/#findComment-753162 Share on other sites More sharing options...
gevans Posted February 3, 2009 Share Posted February 3, 2009 By the sounds of thins he's going to be checking if the id number of a product is in an array so will already have the number to check against, if there are a few products it would still be faster to do this using strpos() And I think you're looking for /\d*/ Quote Link to comment https://forums.phpfreaks.com/topic/143553-solved-php-function/#findComment-753165 Share on other sites More sharing options...
killah Posted February 3, 2009 Author Share Posted February 3, 2009 $errno = $soc['oUPGRADES']; if( strpos($errno,$soc['upID']) !== FALSE ) { echo ' <option value="null">'.$soc['upNAME'].' (Already Bought)</option>'; } Work's so far. Just got to second mysql error. So i will post back when fixed. Work's Quote Link to comment https://forums.phpfreaks.com/topic/143553-solved-php-function/#findComment-753168 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.