How to remove individual special characters from a string in PHP?

I have a line as shown below

Hindustan Times, October 2009, review by a renowned art critic at her solo exhibition in Jaipur, Jawahar Kala Kendra'th, September 23-29, 2009. "Many of her paintings, including her portrait, stress in the humanities, unusual position and aimlessness"

In the line above, I need to remove the following characters

, " ' - .

Are there any string functions that I can use to remove these characters?

+3
source share
4 answers

Alternatively, you can turn off all characters that are not alphanumeric or spaces, rather than listing all characters that you do not want:

preg_replace("/[^A-Za-z0-9\s]/", "", $str);

, , , , .

+1

str_replace

$str = "Hindustan Times, Oct 2009, Review by a well known Art critic on her solo exhibition at Jaipur, Jawahar Kala Kendra'th, 23-29th Sep 2009. \"Many of her paintings including her self portrait, stress in humanities singular plight and aimlessness";
$search     = array(',', '"', "'", '-', '.');
$clean      = str_replace($search, ' ', $str); 
echo $clean; 
+3

preg_replace .

0

JohnP str_replace(). , (, , ).

, , .

, , , - , , .

preg_replace('/[,"\'.-]+/', '', $str);

Ideone.

0

All Articles