| 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,208
|
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. |
|
|
|
#12 (permalink) |
|
Steady on, old chap.
Join Date: Sep 2010
Location: 1960's.
Posts: 2,392
|
Fuck - another nugget. For those of you looking for a good CMS, try:
Ionize CMS - nothing to do with me but a fucking brilliant, comprehensive CMS which uses a MYSQL database. GetSimple CMS - still nothing to do with me but this comprehensive CMS doesn't need a database. Monstra CMS - again, nothing to do with me but this is a clean and simple, lightweight CMS. Sitecake - you guessed it (nowt to do with me) but this CMS is a simple, neat inline content editing system. |
|
![]() |
|