preg_replace () replace only the first result why?
function filter($data) { $oldString = array('😀','😃','😄'); $newString = array('smile1','smile2','smile3'); return str_replace($oldString, $newString, $data); } function smile($data) { $data = preg_replace_callback('/[\x{80}-\x{10FFFF}]/u', function ($m) { $char = current($m); $utf = iconv('UTF-8', 'UCS-4', $char); return sprintf("&#x%s;", ltrim(strtoupper(bin2hex($utf)), "0")); }, $data); preg_match_all("/(&#[a-zA-Z0-9]{6};)/", $data, $hashtweet); foreach ($hashtweet[1] as $ht){ $data = preg_replace("/(&#[a-zA-Z0-9]{6};)/", filter(strtolower($ht)), $data); } $data = mb_convert_encoding($data, 'UTF-8', 'HTML-ENTITIES'); return $data; } echo smile('😀 😃 😄'); Here is the result.
smile1 smile1 smile1
If you replace echo str_replace($oldString, $newString, $data); then I get this result. (Generally wrong)
smile1smile2smile3
How to make such a result
smile1 smile2 smile3
PS Is there another option ?!
😀 😃 😄😀 😃 😄these codes are so smilesπ π π- KYRANΠΡΠΈΠ²Π΅Ρ πand this code is looking for smiles and replaced with the wordsΠΡΠΈΠ²Π΅Ρ smile1- KYRANmb_convert_encoding($data, 'UTF-8', 'HTML-ENTITIES');- KYRAN