1
I have a string = "/var/www*/te'st/test.php" and I want to be able to clear all the 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);
1
I have a string = "/var/www*/te'st/test.php" and I want to be able to clear all the 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);
1
Do it like this:
$string = "/var/www*/te'st/test.php";
$string = preg_replace( '/[^A-Za-z0-9\-\\.\/]/' , '' , $string );
echo $string;
Browser other questions tagged php
You are not signed in. Login or sign up in order to post.
The problem you have with this regex at the moment
– Isac
@Isac from what I understand, he wanted the string /var/www/test/test.php. This regex he used, returns varwwwtesttestphp
– Andrei Coelho
@Andreicoelho Yes I also tested and realized this, but who looks at the question may not be able to understand what the problem the author is having. If you stay in the question it’s clearer to everyone.
– Isac
@Isac yes.. has rasão!
– Andrei Coelho