Created
April 1, 2021 13:34
-
-
Save lauroguedes/5bf0fd609690935c14341c7e650a119c to your computer and use it in GitHub Desktop.
Remove Emojis in Laravel PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (!function_exists('removeEmojis')) { | |
| function removeEmojis($data) | |
| { | |
| $regex = '/([^-\p{L}\x00-\x7F]+)/u'; | |
| if (is_string($data)) { | |
| return preg_replace('/^\s+|\s+$|\s+(?=\s)/', '', preg_replace($regex, '', $data));; | |
| } | |
| $modified = collect($data)->map(function ($item, $key) use ($regex) { | |
| if (is_string($item)) { | |
| return preg_replace('/^\s+|\s+$|\s+(?=\s)/', '', preg_replace($regex, '', $item)); | |
| } | |
| return $item; | |
| }); | |
| return $modified->all(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment