3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = 'Testing giving dancing 喝 喝 passing 制图 giving 跑步 吃'; // split by a space into an array $explosion = explode(' ', $string); $normalWords = []; $chineseWords = []; // loop through the array foreach ($explosion as $debris) { // if not normal alphabet characters if (!preg_match('#[a-zA-Z]+#', $debris) && !in_array($debris, $chineseWords)) { // add to chinese words array if not already in the array $chineseWords[] = $debris; } elseif (preg_match('#[a-zA-Z]+#', $debris) && !in_array($debris, $normalWords)) { // add to normal words array if not already in the array $normalWords[] = $debris; } } // reverse the chinese characters like you wanted $chineseWords = array_reverse($chineseWords); // Piece it all back together $string = implode(' ', $normalWords) . ' ' . implode(' ', $chineseWords); // and output echo $string;
Output for 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Testing giving dancing passing 吃 跑步 制图 喝
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Testing giving dancing passing 吃 跑步 制图 喝

preferences:
164.13 ms | 402 KiB | 191 Q