Jump to content

splitting some numbers from text


mforan

Recommended Posts

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

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-

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.