0

I'm receiving some information using sockets But it gets some garbage depending the client and the OS.

Example : Receiving "Hello" string

ÿþ^Xÿþ^_ÿþ ÿþ!ÿþ"ÿþ'ÿü^Eÿþ#Hello

That gets stored in a $msg variable. How can i clean it up from those strange characters?. (The characters varies from msg to msg).

Thanks in advance

KillDash9
  • 879
  • 1
  • 8
  • 21
  • http://stackoverflow.com/questions/1401317/remove-non-utf8-characters-from-string this may help you – Sterling Archer May 22 '14 at 17:40
  • 1
    You can use `preg_replace('/[^\w\d]+/', '', strip_tags(html_entity_decode($str)))` to get just letters and numbers. – mts7 May 22 '14 at 17:42
  • 1
    I just used preg_replace('/[^\w\d\s]+/', '', strip_tags(html_entity_decode($str))) and did the trick. Thanks!!! – KillDash9 May 22 '14 at 18:02

1 Answers1

0

Thank you, it worked

preg_replace('/[^\w\d\s]+/', '', strip_tags(html_entity_decode($str)));
Shahbaz
  • 326
  • 5
  • 18