With the help of $ js = file_get_contents I pull out titles that can contain "beauty" in the form of crowns, hearts and other things βžœπŸš€πŸš€πŸš€βžœ 🎣 this is 🎣🎣 query πŸš€ for 🎣🎣 search

Further, the query goes to the search and of course - the search does not work: (

βžœπŸš€πŸš€πŸš€βžœ 🎣 this is 🎣🎣 query πŸš€ for 🎣🎣 search
Can I somehow get rid of the beauty and leave only the text on the fly? Now I use urlencode and str_replace helps a little ...

Thank!

    2 answers 2

    Code

    $str = 'βžœπŸš€πŸš€πŸš€βžœ 🎣 это 🎣🎣 запрос πŸš€ для 🎣🎣 поиска'; $str = preg_replace('/[^\w]+/u', ' ', $str); 

    Result

      это запрос для поиска 

    Test https://regex101.com/r/8SwCIo/1

    PS [^\w] is not a letter, not a number or an underscore, u modifier for regular work with UTF-8.

    PPS Instead of [^\w] you can use \W

       $text = "Π’ΡƒΡ‚ тСкст с emoji"; $text = trim(preg_replace('#\xEE[\x80-\xBF][\x80-\xBF]|\xEF[\x81-\x83][\x80-\xBF]#', '', $text)); echo $text; 
      • ZeroTwink, thanks! - MicroRu
      • That I myself once looked for this, when I worked with emoji for the first time) Do you not mark the answer? ) - ZeroTwink
      • Noted, I have a small karma, does not think so far :( - MicroRu
      • @MicroRu, he meant clicking on the check mark to the left of the answer. - Qwertiy ♦
      • $ text = "1111111β™› βžœπŸš€πŸš€πŸš€βžœ 🎣 this is 🎣🎣 query πŸš€ for 🎣🎣 search β™› 2222222"; Displayed the result 1111111β™› βžœπŸš€πŸš€πŸš€βžœ 🎣 this 🎣🎣 query πŸš€ for search β™› 2222222 Did not work :( - MicroRu