sanity is being lost...array_search problems
Posted: Tue Jan 19, 2010 3:44 pm
Hi guys, was just wondering if anyone would mind helping me, i have been over this millions of times and still cannot see anything wrong with it...but its not working, i appologise for lack of PHP tags, but its just the snippits that are going wrong.
Iv been over this code for the past hour and a half, it all seems right, yet its not working!
I have a function in my program known as splitcsv:
A call to this function is made to create an array in one of my php files, $searched is defined by what the user searches for:
It then goes through a series of If statements,
It appears that when $searchfilefor is set, none of the conditions are true..??
For example:
Iv been over this code for the past hour and a half, it all seems right, yet its not working!
I have a function in my program known as splitcsv:
Code: Select all
function splitcsv($string, $separator=",")
{
$elements = explode($separator, $string);
for ($i = 0; $i < count($elements); $i++) {
$nquotes = substr_count($elements[$i], '"');
if ($nquotes %2 == 1) {
for ($j = $i+1; $j < count($elements); $j++) {
if (substr_count($elements[$j], '"') %2 == 1) { // Look for an odd-number of quotes
// Put the quoted string's pieces back together again
array_splice($elements, $i, $j-$i+1,
implode($separator, array_slice($elements, $i, $j-$i+1)));
break;
}
}
}Code: Select all
$searchfile = splitcsv(file_get_contents("searches.csv"));
// This gets rid of any annoying spaces in the search
array_walk($searchfile, 'trim_value');
// This performs the search itself
$searchfilefor = array_search($searched,$searchfile);Code: Select all
if ($searchfilefor == "")
{
//This will execute if the searched file isnt found, this works perfectly
$fh = fopen("searches.csv", "a");
fwrite($fh, $searched);
fclose($fh);
}
if ($searchfilefor != "")
{
//This however...will not echo, even when $searchfilefor has a value???
echo "Hello World!<br>";
}Code: Select all
//When the value searched is in the searchfile, it will display $searchfilefor number here, so its definatly set
var_dump($searchfile);
echo "<br><br>";
echo "I am trying to find: '$searched' <br> It is located at:".$searchfilefor;I am trying to find: 'jj'
It is located at:7