1

i am working on a function to check an Array if there are special Chars i do not want to have.

The Main Function

public function scan()
{
  $matches = array ();
  foreach ($this->arr_select as $key => $value) {
    if (preg_match_all(StringWorker::getRegex(), $value['filename'], $match)) {
        $matches[$key]['id'] = $value['id'];
        $matches[$key]['filename'] = $value['filename'];
        $matches[$key]['chars'] = $match;
     }
  }
  return $matches;
}

This is the Source Array

Array
(
    [0] => Array
        (
            [id] => 2
            [filename] => image_708_2_41_87026_gg_Mytrauringstore_Verlobungsringe_Saint_Maurice.jpg
        )

    ...

    [6861] => Array
    (
        [id] => 12322
        [filename] => image_2623_йцу.JPG
    )

    ...

    [7162] => Array
    (
        [id] => 12699
        [filename] => image_3050_Ringänderung_Service_kostenlos_Mytrauringstore.jpg
    )

    ...
)

So with this Regex

protected static $regex = '([^a-zA-Z0-9äöüßÄÖÜ_.\-\+]+)';

i get this result

Array
(
    [6861] => Array
        (
            [id] => 12322
            [filename] => image_2623_йцу.JPG
            [chars] => Array
                (
                    [0] => Array
                        (
                            [0] => �¹
                            [1] => �†
                            [2] => �ƒ
                        )

                )

        )

    ...


    [7162] => Array
        (
            [id] => 12699
            [filename] => image_3050_Ringänderung_Service_kostenlos_Mytrauringstore.jpg
            [chars] => Array
                (
                    [0] => Array
                        (
                            [0] => �ˆ
                        )

                )

        )

)

and with this Regex

protected static $regex = '/[\xc2-\xdf][\x80-\xbf]/';

i get this Result

Array
(
    [6861] => Array
    (
        [id] => 12322
        [filename] => image_2623_йцу.JPG
        [chars] => Array
            (
                [0] => Array
                    (
                        [0] => Ð
                        [1] => ¹
                        [2] => Ñ
                        [3] => Ñ
                        [4] => ƒ
                    )

            )

    )


    ...



    [7162] => Array
    (
        [id] => 12699
        [filename] => image_3050_Ringänderung_Service_kostenlos_Mytrauringstore.jpg
        [chars] => Array
            (
                [0] => Array
                    (
                        [0] => Ì
                        [1] => ˆ
                    )

            )

    )

)

So with the second Regex i match the Chars that really exists in the String. But i also matches these Chars

ä ö ü ß Ä Ö Ü

but these Chars should'n match.

So how to manage this?

magic.77
  • 829
  • 1
  • 11
  • 21

0 Answers0