Answers for "php function to clean special characters"

PHP
5

php strip out special characters

function clean($string) {
   $string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.

   return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
}
Posted by: Guest on December-09-2020
0

Remove special characters in php

function removeSpecialChar($string) 
		{
			$string = strtolower($string);
			$string = preg_replace('/[^\da-z ]/i', '', $string);// Removes special chars.
			$string = str_replace(' ', '-', $string); // Replaces all spaces with underscore.
			return strtolower($string);
		}
Posted by: Guest on December-27-2021

Code answers related to "php function to clean special characters"

Browse Popular Code Answers by Language