2
0
mirror of https://github.com/boostorg/website.git synced 2026-01-29 08:02:20 +00:00
Files
website/common/code/boost_utility.php
2007-08-04 20:38:01 +00:00

37 lines
1.2 KiB
PHP

<?php
/*
Copyright 2007 Redshift Software, Inc.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
*/
require_once(dirname(__FILE__) . '/boost.php');
function _preg_replace_bounds($front_regex,$back_regex,$front_replace,$back_replace,$text)
{
$offset = 0;
$result = '';
while (TRUE)
{
$subject = substr($text,$offset);
if (preg_match($front_regex,$subject,$begin,PREG_OFFSET_CAPTURE) == 0 ||
preg_match($back_regex,$subject,$end,PREG_OFFSET_CAPTURE,
$begin[0][1]+strlen($begin[0][0])) == 0
)
{ break; }
else
{
$result .= substr($subject,0,$begin[0][1]);
$result .= preg_replace($front_regex,$front_replace,$begin[0][0]);
$result .= substr(
$subject,
$begin[0][1]+strlen($begin[0][0]),
$end[0][1]-($begin[0][1]+strlen($begin[0][0])) );
$result .= preg_replace($back_regex,$back_replace,$end[0][0]);
$offset += $end[0][1]+strlen($end[0][0]);
}
}
if ($result === '') { return $text; }
else { return $result . substr($text,$offset); }
}
?>