Forum Moderators: coopster
212=RESULT1,213=RESULT2,214=RESULT4,
The numbers are what I want to be able to search and get result. so basically if i want to search for 212 i need to find everything after 212= and before the comma.
can anyone tell me how i can do this ?
thanks
<?php
//if they click the submit button
if(isset($_POST['submit'])){
//a boolean for no results returned
$noResult = true;
//the input from the user
$input = $_POST['input'];
//the data in the format you gave
$data = "1=RESULT1,13=RESULT2,214=RESULT4,215=RESULT4,216=RESULT4,216=RESULT4,217=RESULT4";
//split the array based on a comma
$tempArr = split(",", $data);
//now go through the array and search for the number
foreach($tempArr as $i){
//the position of the =
$tempPos = stripos($i, "=");
$tempNum = substr($i, 0, $tempPos);
$tempData = substr($i, $tempPos + 1);
if($input == $tempNum){
echo("Your result is $tempData");
$noResult = false;
break;
}//if
}//foreach
if($noResult){
echo("Sorry, your search did not return any results.");
}//if noresult
}//if isset
?>
</body>
</html>