mforan Posted May 3, 2010 Share Posted May 3, 2010 Hi, i need a bit of advice on how to split some text... basically i want to turn the text "1,3,5,6,8,9" into individual numbers on there own. basically i need to enter the numbers into an IF like: if ($number = "1" || "3" || "5" || "6" || "8" || "9") { echo "blah"; } i need the IF statement to corrispond to the numbers in the original text everytime. any ideas? Link to comment https://forums.phpfreaks.com/topic/200506-splitting-some-numbers-from-text/ Share on other sites More sharing options...
ChemicalBliss Posted May 3, 2010 Share Posted May 3, 2010 First you split the string into an array: $string = "1,3,5,6,8,9"; $strArray = explode(",",$string); Then you would loop the array, and echo just once if a match is found; foreach($strArray As $number2){ if($number == $number2){ echo("blah"); break; } } -cb- Link to comment https://forums.phpfreaks.com/topic/200506-splitting-some-numbers-from-text/#findComment-1052170 Share on other sites More sharing options...
Alex Posted May 3, 2010 Share Posted May 3, 2010 Not sure, but I think you meant something like this: $string = "1,3,5,6,8,9"; if(in_array($number, explode(',', $string))) { // ... } Link to comment https://forums.phpfreaks.com/topic/200506-splitting-some-numbers-from-text/#findComment-1052171 Share on other sites More sharing options...
mforan Posted May 3, 2010 Author Share Posted May 3, 2010 ahhhh awesome, i didnt know about "foreach" works, very, very nicely! thanks! Link to comment https://forums.phpfreaks.com/topic/200506-splitting-some-numbers-from-text/#findComment-1052178 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.