tags:

views:

47

answers:

2

I need to remove everything (parentheses, punctuation, etc), using PHP, from a text string and leave just text.

Someone suggested this:

$str= trim(preg_replace('/\s*\([^)]*\)/', '', $str));

Also, if there are words like: Bob's it needs to be cleaned to Bob. I also do not need any numbers, just words separated by commas.

Any suggestions would be great!

A: 

Use:

$str = trim(preg_replace('/[^A-Za-z]/', '', $str));

This will replace everything that isn't A-Z or a-z (i.e., everything that isn't a letter).

VoteyDisciple
A: 

The following will replace anything that's not a letter or comma as described in your OP. However, it will not change Bob's to Bob. If that's what you require, comment back with more examples.

$str = trim(preg_replace('/[^a-zA-Z,]/', '', $str))
Jason McCreary