Hello,
"Galkov Vladimir" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Need to remove all "../" "/.." from user inputing string to prevent him
> walking and creating files&directories where I don't whant see them/him...
>
> The string:
>
> $path =
> eregi_replace('([..]{2,})|([./]{2})|([../]{3,})|([/.]{2})|([/..]{3})', '',
> $path);
>
> works good with any combinations ( ../../..qwert.txt => qwert.txt)
untill
> somth like "/../asd/../qwert.txt" will be entered ...
(/../asd/../qwert.txt
> => asdqwert.txt).
> So the qwestion is how upgrade regular expression to remove all this
> correctly (with all entered directory names but NOT assigned their names
to
> file name...
>
> Must do the operation:
> /../asd/......../qwert.txt => qwert.txt
> but not => /asd/qwert.txt or asdqwert.txt.ru
> or
> /................../asd/../qwert.txt.ru => qwert.txt.ru
> but not => /asd/qwert.txt.ru or asdqwert.txt.ru
>
Try this:
<?
$string = "/../asd/......../qwert.txt";
$string = preg_replace("/(\.*\/\.?)+.*?(\.*\/)?/s", "", $string);
echo $string;
?>
May need some tweaking, let me know.
~James
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]