RhymeGuy RhymeGuy - 3 months ago 25
PHP Question

PHP / Replace non latin characters with its counterparts

WORD

AŠA


PHP

<?php

foreach (glob("*.jpg") as $filename) {
$search = array("Š");
$replace = array("S");

$newname = str_replace($search, $replace, $filename);
echo $filename.'<br>'.$newname;

//($filename, realpath(dirname(__FILE__)).'/'.$newname);
}


PROBLEM
It does not replace character "Š" in word "AŠA"

Answer

Take a look at iconv() which allows you to convert a string to a specified encoding.

Example for your case:

$str = 'AŠA';
$str = iconv('UTF-8', 'ASCII//TRANSLIT', $str); // ASA