...

View Full Version : Resolved REGEX help needed: exclude all non-word except hyphen ??



mOrloff
01-21-2010, 07:22 PM
I am using this code:

$text=preg_replace('/\W/', ' ', $body); // strip all punctiation and non-word characters

But have come to realize that I need to keep the hyphens.

What is the easiest way to srtip all non-word characters except the hyphen?
Is there a way to make an exception for "-" while using \W, or some other direct way of doing it?

~ Mo

mOrloff
01-21-2010, 08:51 PM
I figured it out. Thanks anyhow.
I changed it to:

$text=preg_replace('/[^A-Za-z0-9-]/', ' ', $body); // strip all punctuation and non-word characters

~Mo

JAY6390
01-22-2010, 02:50 AM
Could have also used /[\W-]/



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum