Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Closed
wants to merge 1 commit into from

Conversation

fancyweb
Copy link
Contributor

@fancyweb fancyweb commented Jan 2, 2023

Q A
Branch? 6.3
Bug fix? no
New feature? yes
Deprecations? no
Tickets #48850
License MIT
Doc PR -

Add the stripEmojis() shortcut method to easily strip emojis from any string by leveraging the special strip locale from the EmojiTransliterator.

@fancyweb fancyweb force-pushed the string/strip-emojis branch from cd993e1 to 55c89a7 Compare January 2, 2023 12:48
@nicolas-grekas
Copy link
Member

nicolas-grekas commented Jan 2, 2023

Thanks for the PR.
I was reluctant to add the rule so I'm also reluctant to add this method.
What is the use case? Why strip emojis instead of any other transliteration rule? Why emojis and not eg CJKs, Greek, etc.?

@nicolas-grekas
Copy link
Member

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.

@javiereguiluz
Copy link
Member

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 ? and other weird characters.

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 😢

@fancyweb
Copy link
Contributor Author

fancyweb commented Jan 3, 2023

Why emojis and not eg CJKs, Greek, etc.?

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.

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Jan 5, 2023

I would like to gather more use cases before adding a shortcut to a feature that already exists.
Thanks @javiereguiluz for yours. To me it looks like a font issue: the font used to render the content doesn't provide glyphs for emojis. But maybe it doesn't provide either for CJK/etc. Maybe a proper solution would be to find another font (or fallback font for emojis.)

@javiereguiluz
Copy link
Member

Here's another possible use case: your database supports UTF8 but, for some reasons, doesn't support the utf8mb4 needed to store emojis properly. You want to do $comment->setContent($form->getContent()->stripeEmojis()) before persisting it to avoid issues.

@stof
Copy link
Member

stof commented Jan 5, 2023

@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.

@stof
Copy link
Member

stof commented Jan 5, 2023

Btw, having this method in AbstractString is flawed to me as it assumes that the string is in UTF-8

@nicolas-grekas
Copy link
Member

Given the confusion level about the feature, I'd suggest rejecting.

@fabpot
Copy link
Member

fabpot commented Jan 10, 2023

I agree with @nicolas-grekas.
It's either doing too much or not enough.
Let's close.

@fabpot fabpot closed this Jan 10, 2023
@MolloKhan
Copy link
Contributor

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

@OskarStark
Copy link
Contributor

Can you please open a new issue to keep track of your feedback? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants