0

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.

1
  • Do you want to remove just parentheses or also text within them? The code you posted also removes the text inside parentheses. Commented Oct 12, 2010 at 2:01

3 Answers 3

2

Use:

$str = 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).

Sign up to request clarification or add additional context in comments.

Comments

0

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))

Comments

0

Please Use this if you want only string from tags and script.

echo strip_tags(html_entity_decode($string_data));

I think this method will help you to get all text from script or tags it can be used to split individual tag also. like this :

echo strip_tags(html_entity_decode($string_data),"<p>");
echo strip_tags(html_entity_decode($string_data),"<a>");
echo strip_tags(html_entity_decode($string_data),"<span>");

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.