0
$string = "' ! ; • ,\ KarSho: ; • ;}";

Here I want remove following characters,

$remove = array("'","!",";","•",",","\","}","{","[","]");

This is also input. I want from above array characters from $string. Finally I want string like,

KarSho:

KarSho
  • 5,699
  • 13
  • 45
  • 78

2 Answers2

2

Use the following code:

$remove = ["'","!",";","•",",","\\","}","{","[","]"," "];
$replace_with = [];
$string = "' ! ; • ,\ KarSho: ; • ;}";
print str_replace($remove, $replace_with, $string);

You need to add one more \ with \

Francisco Luz
  • 2,775
  • 2
  • 25
  • 35
amarjeet kumar
  • 345
  • 1
  • 10
0

You can use this code

$string = "' ! ; • ,\ KarSho: ; • ;}";
echo $new_str = str_replace(str_split('\\/!;•,}:*?"<>|'), ' ', $string);
Sunil Pachlangia
  • 2,033
  • 2
  • 15
  • 25