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:

3
  • the issue is the backslash ,"\","}","{","[","]"); try add extra " before \ sign.. like ""\" Commented Jun 26, 2015 at 10:54
  • Look at the str_replace() solution (And don't forget to escape the backslash) Commented Jun 26, 2015 at 10:55
  • $new_string = str_replace($remove,"",$string); Commented Jul 3, 2015 at 6:22

2 Answers 2

2

Use the following code:

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

You need to add one more \ with \

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

Comments

0

You can use this code

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

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.