How to check and add a / in a path

0

I have a form where the user will type a particular path, eg: / 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 it has not typed to make it include,     

asked by anonymous 04.07.2018 / 22:34

1 answer

0

You can do this as follows:

$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 += '/';
}
    
05.07.2018 / 02:55