homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Search for value of a search criteria

 7:04 pm on Sep 10, 2009 (gmt 0)

I have a text file that's content is loaded into a variable and it looks like this:


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 ?




 9:25 pm on Sep 10, 2009 (gmt 0)

Try this
<form name="form" method="post">
Search: &nbsp; <input type="text" name="input" /><br>
<input type="submit" name="submit" value="submit" />


//if they click the submit button

//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;



echo("Sorry, your search did not return any results.");

}//if noresult

}//if isset



 9:33 pm on Sep 10, 2009 (gmt 0)

Note: the above code will return true if a user enters 0214 for the value 214 because it is checking their numerical values. If you want to check every digit exactly then convert them to strings i.e.
if($input === $tempNum){ //added and extra =


 10:08 pm on Sep 10, 2009 (gmt 0)

thanks works perfectly

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved