![]() |
VOOZH | about |
We are given a string and the task is to remove special characters from string str in PHP.
Below are the approaches to remove special characters from string in PHP:
The str_replace() method is used to remove all the special characters from the given string str by replacing these characters with the white space (" ").
str_replace( $searchVal, $replaceVal, $subjectVal, $count )Example: This example illustrates the use of the str_replace() function to remove the special characters from the string.
Output:
Example to remove the Special CharThe str_ireplace() method is used to remove all the special characters from the given string str by replacing these characters with the white space (" "). The difference between str_replace and str_ireplace is that str_ireplace is case-insensitive.
str_ireplace( $searchVal, $replaceVal, $subjectVal, $count )Example: This example illustrates the use of the str_ireplace() method to remove all the special characters from the string.
Output:
Example to remove the Special CharThe preg_replace() method is used to perform a regular expression for search and replace the content.
preg_replace( $pattern, $replacement, $subject, $limit, $count )Example: This example illustrates the use of the preg_replace() method where the particular or all the matched pattern found in the input string will be replaced with the substring or white space.
Output:
Example to remove the Special Char