| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
|
|
#1 (permalink) |
|
Registered User
Join Date: Nov 2005
Posts: 57
|
php remove punctuation
Hi, i was wondering if there was a php function that removes all punctuation from a string of text. I can filter out full stops, commas etc using regex but thought surely there must be a function to do all punctuation. Have looked through the manual but could find anything. |
|
|
|
|
|
#3 (permalink) |
|
Senior Member
Join Date: Sep 2004
Posts: 149
|
Skidzy McFergus, Do you anticipate unicode characters in the string? If so try this: $cleanUnicodeStr = trim(preg_replace('#[^\p{L}\p{N}]+#u', ' ', $unicodeStr)); This will also clean up shitty unicode punctuation like those smily faces, musical quotations and stars etc, whilst at the same time allow for Japanese symbols and other such characters. |
|
|
|
#6 (permalink) |
|
I Ain't Losing Any Sleep™
Join Date: Apr 2003
Posts: 5,237
|
I'm not exactly sure what you mean by support, but I guess you'd want to use a function that supports multibyte characters. http://uk2.php.net/mb_ereg_replace |
|
|
|
#7 (permalink) |
|
Senior Member
Join Date: Sep 2004
Posts: 149
|
preg_replace supports unicode, by using the "u" modifier. Without setting the "u" unicode modifier the string will be interpreted as a string of bytes and will not recognise multibyte unicode characters as individual items to be matched. Obviously cutting part way thru a multibyte character will fuck up the string royally causing a few heart aches on a internationalised application. |
|
![]() |