I have a string="/var/www*/te'st/test.php" and I want to be able to clear all special characters, to get a string like /var/www/test/test.php
$string = "/var/www*/te'st/test.php";
$string = preg_replace('/[^A-Za-z0-9\-]/', '', $string);
I have a string="/var/www*/te'st/test.php" and I want to be able to clear all special characters, to get a string like /var/www/test/test.php
$string = "/var/www*/te'st/test.php";
$string = preg_replace('/[^A-Za-z0-9\-]/', '', $string);
Do this:
$string = "/var/www*/te'st/test.php";
$string = preg_replace( '/[^A-Za-z0-9\-\.\/]/' , '' , $string );
echo $string;