Skip to content

Instantly share code, notes, and snippets.

@insideone
Last active May 15, 2016 13:36
Show Gist options
  • Save insideone/b401baca09a67a3c802dfae405c0e894 to your computer and use it in GitHub Desktop.
Save insideone/b401baca09a67a3c802dfae405c0e894 to your computer and use it in GitHub Desktop.
PHP: webpath/syspath
<?php
/**
* Получает имя файла относительно корня сайта
* @param string $syspath Полное имя файла
*/
function syspath($webpath)
{
return preg_match('~^('.$_SERVER['DOCUMENT_ROOT'].')~', $webpath) ? $webpath : $_SERVER['DOCUMENT_ROOT'].$webpath;
}
<?php
/**
* Получает имя файла относительно корня сайта
* @param string $syspath Полное имя файла
*/
function webpath($syspath)
{
return preg_replace('~^('.$_SERVER['DOCUMENT_ROOT'].')~', '', $syspath);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment