- substr: documentation ( source)
<?php
$prefix = "/opt/git/repositories/";
$cwd = "/opt/git/repositories/libs/commponent/common";
$gitwebUrl = 'http://packagist.alpari-ru.dom';
if (substr($cwd, 0, strlen($prefix))) {
$relative = substr($cwd, length($prefix) + 1);
echo "$gitwebUrl/$relative";
} else {
echo "error";
}