Skip to content

Instantly share code, notes, and snippets.

@lauroguedes
Created April 1, 2021 13:34
Show Gist options
  • Select an option

  • Save lauroguedes/5bf0fd609690935c14341c7e650a119c to your computer and use it in GitHub Desktop.

Select an option

Save lauroguedes/5bf0fd609690935c14341c7e650a119c to your computer and use it in GitHub Desktop.
Remove Emojis in Laravel PHP
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