How to check and add a / in a path

Asked

Viewed 23 times

0

I have a form where the user will type a certain path, example: /var/www... I want to check if the user typed a / at the end example /var/www/.../, that is if the last character was a /, if he did not type to include it, how do I do this in php?

1 answer

0


You can do it this way:

$caminho = $_POST['caminho'];
 // nisso ele pegará o último caracter do caminho e verificará se é uma barra,
 // se não for ele adicionará
$barra = substr($caminho, -1);
if ($barra != '/'){
    $caminho += '/';
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.