$content = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit [image_1|Просто текст], sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in [image_2|Просто второй текст] reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. [image_3|Тестовый текст] Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
$content = preg_replace_callback('/\[[A-z0-9_]+\|([^\]]+)]/', function ($matches) {
return '<img src="" alt="' . $matches[1] . '">';
}, $content);
echo $content;
function rel2abs($rel, $base)
{
/* return if already absolute URL */
if (parse_url($rel, PHP_URL_SCHEME) != '') return $rel;
/* queries and anchors */
if ($rel[0]=='#' || $rel[0]=='?') return $base.$rel;
/* parse base URL and convert to local variables:
$scheme, $host, $path */
extract(parse_url($base));
/* remove non-directory element from path */
$path = preg_replace('#/[^/]*$#', '', $path);
/* destroy path if relative url points to root */
if ($rel[0] == '/') $path = '';
/* dirty absolute URL */
$abs = "$host$path/$rel";
/* replace '//' or '/./' or '/foo/../' with '/' */
$re = array('#(/\.?/)#', '#/(?!\.\.)[^/]+/\.\./#');
for($n=1; $n>0; $abs=preg_replace($re, '/', $abs, -1, $n)) {}
/* absolute URL is ready! */
return $scheme.'://'.$abs;
}
$path = "/files/pages/test_image.jpeg";
$ext = pathinfo($path, PATHINFO_EXTENSION);
$file = basename($path, "." . $ext);
echo $file;