Reputation: 2521
I want to remove the following special character from my string.
:
'
""
`
``
how can i remove each of the above character from my string?
Upvotes: 0
Views: 237
Reputation:
This is a more efficient solution than using preg_replace, which uses regular expressions:
$string = str_replace(array(':',"'",'"','`'), '', $sourceString);
You can read more about str_replace and preg_replace at the php docs:
Upvotes: 0
Reputation: 3887
Use str_replace:
$to_remove = array(':', "'", '"', '`'); // Add all the characters you want to remove here
$result = str_replace($to_remove, '', $your_string);
This will replace all the characters in the $to_remove array with an empty string, essentially removing them.
Upvotes: 4
Reputation: 29498
You could use preg_replace
$string = preg_replace('/[:'" `]/', '', $string);
Upvotes: 1