我想改变这个字符串
测试 - GGAökologieGeschäftsführer.PDF
进入这个:
测试_-_ gga_oekologie_geschaaeftsfuuehrer.pdf
这是我尝试过的:
$characters = array('ä', 'ö', 'ü', 'Ä', 'Ö', 'Ü', ' ');
$converted_characters = array('ae', 'oe', 'ue', 'AE', 'OE', 'UE', '_');
$string = 'Test - GGA o?kologie Gescha?ftsfu?hrer.PDF';
echo strtolower(str_replace($characters, $converted_characters , $string));
Run Code Online (Sandbox Code Playgroud)
上面的代码返回:test _-_gga_ökologie_geschäftsführer.pdf
如您所见,字符串仍包含字符ö和ä.
我的代码出了什么问题?
小智 5
用正则表达式
$characters = array('/ä/u', '/ö/u', '/ü/u', '/Ä/u', '/Ö/u', '/Ü/u', '/ /' );
$converted_characters = array('ae', 'oe', 'ue', 'AE', 'OE', 'UE', '_');
$string = 'Test - GGA ökologie Geschäftsführer.PDF';
echo strtolower(preg_replace($characters, $converted_characters , $string));
Run Code Online (Sandbox Code Playgroud)