Hi
I'm using the following to filter results from specific lines of a text file.
But I have one slight issue.. The example below shows the issue :
<?php
$line = "1=\"Device\",3=\"User\",7=\"ID123456\",27=\"Node\"";
$q = explode(",",str_replace('"','',$line));
$p = (search_array($q, "7=")); echo "ID : ".$p;
function stipos($haystack, $needle){
return strpos($haystack, stristr( $haystack, $needle ));
}
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;
}
?>
I'm search for 7= and then expect to return the value associated to that. In this example, I'd expect : ID123456
However I have an additional entry in $line that is 27=\"Node\"
So the result I actually get is 2Node, not ID123456
I only want a match on 7= and NOT 17= or 27= which it's currently doing.
How do I change the to only return the value against 7= and not a mix of 27= & it's value ??
Thanks