php set path using preg_match / preg_replace?

1

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);
    
asked by anonymous 13.05.2018 / 21:12

1 answer

1

Do this:

$string = "/var/www*/te'st/test.php";
$string = preg_replace( '/[^A-Za-z0-9\-\.\/]/' , '' , $string );
echo $string;

See working on Ideone

    
13.05.2018 / 21:44