2014-05-22 78 views
0

我正在使用套接字接收一些信息 但是,根據客戶端和操作系統的不同,它會有一些垃圾。PHP清除字符串中的奇數字符

例如:接受 「你好」 字符串

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

這被存儲在$味精變量。我怎樣才能從那些奇怪的角色清理它? (字符從msg到msg不等)。

在此先感謝

+0

http://stackoverflow.com/questions/1401317/remove-non-utf8-characters-from-string這可能會幫助你 –

+1

你可以使用'preg_replace('/ [^ \ w \ d] + /','',strip_tags(html_entity_decode($ str)))'來得到字母和數字。 – mts7

+1

我剛剛使用了preg_replace('/ [^ \ w \ d \ s] + /','',strip_tags(html_entity_decode($ str)))並且做了訣竅。謝謝!!! – KillDash9

回答

0

謝謝你,它的工作

preg_replace('/[^\w\d\s]+/', '', strip_tags(html_entity_decode($str))); 
+0

請不要添加「謝謝」作爲答案。相反,投票答案,你覺得有幫助。 - [來自評論](/ review/low-quality-posts/11136065) –

+0

接下來我會記住這一點。 – Shahbaz