简体   繁体   中英

strpos() stripos() problems php

I know this is a regular question and I'm not trying to join the group of people who don't know that strpos() returns the position of the string, and if you want to compare wether it is found or not you have to use the === or the ==! comparision.

My problem is that, strpos has worked fine everytime, but now it seems to have a problem which I can't find, maybe because I have been looking at it for too long.

My code is like this:

$tmp = scandir("img/products");
$productImgs = array();

foreach ($tmp as $key => $value) {
    foreach ($subCats as $_subItem) {
        $_tmp = $_subItem["SUB_CAT"];
        echo $value." => ".$_tmp."<br>";

        if (strpos(rtrim($value), rtrim($_tmp)) !== FALSE) {
            $productImgs[] = $value;
            echo "lol<br>";
        }
    }
}

It basically stores pictures in the tmp array then it loops through all the subCats array to see if there's a match. For eg.:

$_subItem["SUB_CAT"] = "Microplate leolvasók"  
$value = "Microplate leolvasók.jpg"

As I echo out all the values there seems to have a match, but it doesn't get added to the array whatsoever.

It prints out this: Microplate leolvasók.jpg => Microplate leolvasók

I seem to have found no difference between the two strings apart from the .jpg ending but it shouldn't count because of the function of strpos(). My strings are in utf8 for $subCats array, and for $tmp array, it is what scandir gives you back. The directory is not protected, it, and the file can be read and written.

Any idea why doesn't it match?

Thanks in advance!

The accent on the 'o' in leolvasók != leolvasók. Basically the and ó are different.

With the font you use they may look the same. For me, on Firefox, under Linux there is a slight visual difference.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM