clean text string
I need to remove everything (parentheses, punctuation, etc), using PHP, from a te开发者_运维知识库xt 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.
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).
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))
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>");
精彩评论