I use this function to search arrays:
function search_array ( $array, $term )
{
foreach ( $array as $key => $value )
if ( stipos( $value, $term ) !== false )
$val = str_replace('"',"",preg_replace("/[a-zA-Z0-9]=/","",$array[$key]));
if (isset($val)) return $val;
return false;
}
This works well, but I need to make is slightly more restrictive.
$a = (search_array($l, "7=")); echo "Device ID: $a";
This works, but I only want a match on 7= and NOT 17= or 27= which it’s currently doing.
Any idea how I make this ONLY match on what I enter and not try to expand on it ?
Sorry I should have included this function that I’m using in PHP4.
function stipos($haystack, $needle){
return strpos($haystack, stristr( $haystack, $needle ));
}
The entrys are similar to ;
1=”Device”, 3=”User”, 7=”ID123456″, 27=”Node” etc
If I’m searching for 7=, I’d expect the returned result to be ID123456
Currently I get 2Node being returned which is take from 27=”Node”
This is an example of how I’m using this :
$line = "1=\"Device\",3=\"User\",7=\"ID123456\",27=\"Node\"";
$q = explode(",",str_replace('"','',$line));
$p = (search_array($q, "7=")); echo "ID : ".$p;
I’m looking to return 7=, but I get the value of 27= and the initial 2 from it, resulting in
ID : 2Node
Not
ID : ID123456
Resolved using :