Bunun mümkün olmadığını düşünüyorum. Sen isteğe bağlı dördüncü parametresi değiştirmeleri bir sınırı belirleyebilirsiniz, ama bu her zaman başında başlar.
Bu preg_split()
. You would just have to split your string on all occasions of your search pattern and then mess with them one by one. If your search pattern is just a simple string, you can achieve the same with explode()
ile aradığınızı elde etmek mümkün olabilir. Bu yaklaşımı bulmaktan yardıma ihtiyacınız varsa, ben yardımcı olmaktan mutluluk duyarız.
EDIT: Bu sizin için çalışıyor Bakalım:
$subject = 'a b a';
$pattern = '/a/';
$replace = 1;
// We split the string up on all of its matches and obtain the matches, too
$parts = preg_split($pattern, $subject);
preg_match_all($pattern, $subject, $matches);
$numParts = count($parts);
$results = array();
for ($i = 1; $i < $numParts; $i++)
{
// We're modifying a copy of the parts every time
$partsCopy = $parts;
// First, replace one of the matches
$partsCopy[$i] = $replace.$partsCopy[$i];
// Prepend the matching string to those parts that are not supposed to be replaced yet
foreach ($partsCopy as $index => &$value)
{
if ($index != $i && $index != 0)
$value = $matches[0][$index - 1].$value;
}
// Bring it all back together now
$results[] = implode('', $partsCopy);
}
print_r($results);
Not: Bu henüz test edilmemiştir. Çalışıp çalışmadığını bildiriniz.
EDIT 2:
Ben şimdi, bir kaç şey sabit ve (en azından bu örnek ile) artık çalışıyor sizin örnek ile test edilmiştir.