-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[String] Add the stripEmojis() method #48853
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
cd993e1
to
55c89a7
Compare
Thanks for the PR. |
To me it feels like playing against Unicode and I want to know why we should make it easy to restrict the range of possible characters humans can use to communicate. |
Just to add to the discussion, here's a real use case of mine in a Symfony app. In some part of a website, we have some entity titles that are allowed to include emojis (and some do). In other part of the website, we generate a PDF with that same information. Our PDF tool doesn't support emojis, so we must strip them from the original contents to avoid printing Today we're removing the emojis manually with a regex that I copied from Stack Overflow ... I've already updated the regex twice and it's still missing some emojis 😢 |
I never had to work on an application that had to deal with CJKs or Greek but I did work on applications dealing with emojis a few times. I think it's more likely for a random Symfony dev to have to deal with emojis than other exotic ranges. Adding this method looks like a nice DX addition to me. Googling "php remove emoji" give some results and there are some libraries dedicated to that so I guess there are some legitimate use cases. |
I would like to gather more use cases before adding a shortcut to a feature that already exists. |
Here's another possible use case: your database supports UTF8 but, for some reasons, doesn't support the |
@javiereguiluz not all Unicode characters needing 4 bytes in the UTF-8 encoding are emojis (and not all emojis are encoded as 4 bytes either IIRC). So this use case is still a broken one related to a misunderstanding of the issue. |
Btw, having this method in AbstractString is flawed to me as it assumes that the string is in UTF-8 |
Given the confusion level about the feature, I'd suggest rejecting. |
I agree with @nicolas-grekas. |
I know this issue is already closed but here's another use case for this feature. In SymfonyCasts, we use a third-party service to generate video captions. It requires sending the script file which may contain emojis and that causes trouble. So, I need to remove them before sending the file to the third-party service |
Can you please open a new issue to keep track of your feedback? Thanks |
Add the
stripEmojis()
shortcut method to easily strip emojis from any string by leveraging the specialstrip
locale from theEmojiTransliterator
.