Sjorsman Posted March 20, 2013 Share Posted March 20, 2013 I'm trying to filter out the rows of a uploaded csv that have the word "lokaal" (classroom) in the 3th colom, but this doesn't work. What does work: When I search for just one letter (for example the o) $findneedle is true, so it works Putting $haystack="lokaal 5"; in the coding also works (but that is just usable for testpurposes) echo $haystack does result in a correct value, so the csv is read correctly <? $handle = fopen($_FILES['file']['tmp_name'], "r"); $data = fgetcsv($handle, 1000, ";"); //Remove if CSV file does not have column headings while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) { $haystack=$data[2]; $needle='lokaal'; $findneedle=strpos($needle, $haystack); if($findneedle !== false) { //rest of the coding } ?> The CSV looks like this 2013;Class 1;Zelfstudie;31-12-2013 0:00:00;1-1-1900 9:00:00;1-1-1900 12:00:00; 2013;Class 2;lokaal 5;27-12-2013 0:00:00;1-1-1900 15:00:00;1-1-1900 17:00:00; Am I overlooking something? I hope someone can help me. Quote Link to comment https://forums.phpfreaks.com/topic/275906-search-in-string-doesnt-work/ Share on other sites More sharing options...
Barand Posted March 20, 2013 Share Posted March 20, 2013 int strpos ( string $haystack , mixed $needle [, int $offset = 0 ] ) check manual Quote Link to comment https://forums.phpfreaks.com/topic/275906-search-in-string-doesnt-work/#findComment-1419777 Share on other sites More sharing options...
Sjorsman Posted March 20, 2013 Author Share Posted March 20, 2013 Thanks for the reply. I made a mistake when I created the topic. My original coding is in Dutch and when I rewrote the variable names to needle and haystack I switched them. This is how it should have been. Sorry for this stupid mistake. <? $handle = fopen($_FILES['file']['tmp_name'], "r"); $data = fgetcsv($handle, 1000, ";"); //Remove if CSV file does not have column headings while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) { $haystack=$data[2]; $needle='lokaal'; $findneedle=strpos($haystack, $needle); if($findneedle !== false) { //rest of the coding } ?> Quote Link to comment https://forums.phpfreaks.com/topic/275906-search-in-string-doesnt-work/#findComment-1419785 Share on other sites More sharing options...
Barand Posted March 20, 2013 Share Posted March 20, 2013 Is it working now? You didn't say. Quote Link to comment https://forums.phpfreaks.com/topic/275906-search-in-string-doesnt-work/#findComment-1419937 Share on other sites More sharing options...
Sjorsman Posted March 21, 2013 Author Share Posted March 21, 2013 Nope, still doesn't work. I've been experimenting further and it looks like it's a charset problem, because when I re-save the csv-file as an UTF-file (in Notepad) and upload that one, everything works fine. If I do a mb_detect_encoding on the $haystack it echo's ASCII. Since ASCII is a subset of UTF-8, to me it doesn't make sense why it does work when I re-save the file as UTF8. Now I'm trying to do the re-save automatically by php. I've playing around with mb_convert_encoding, iconv and utf8_encode, but with no succes so far. If anyone has good suggestions for it, please let me know. Quote Link to comment https://forums.phpfreaks.com/topic/275906-search-in-string-doesnt-work/#findComment-1420073 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.