how to remove special character from string php code example
Example 1: 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.
}
Example 2: Remove Special Character in PHP
phpCopy<?php
$str = "geeks";
$str = ltrim($str, 'g');
echo $str;
?>