<?php
$string = "The new Intel Core 2 Duo T8300";
$name = "Intel Core 2";
$extra = " Duo";
$insert = " Processor Technology";
echo preg_replace("/({$name}{$extra}?)/", "$1".$insert, $string);
?>
Simcha Younger
-----Original Message-----
From: Adz07 [mailto:[EMAIL PROTECTED]
Sent: Monday, August 18, 2008 10:17 AM
To: [email protected]
Subject: Re: [PHP] preg_replace strange behaviour, duplicates
Problem is that a negative assertion assumes i know what is going to come
after the match, but i don't. I am a bit stuck now :(
Adz07 wrote:
>
> I am trying to nail down a bit of code for changing processor names
> depending on matches.
> Problem i am having is the replacement takes place then it seems to do it
> again replacing the text just replaced as there are similar matches
> afterwards. example (easier)
>
> $string = "The new Intel Core 2 Duo T8300";
>
> $patterns = array("/Intel Core 2 Duo/","/Intel Core 2/");
>
> $replacements = array("Intel Core 2 Duo Processor Technology","Intel Core
> 2 Processor Technology");
>
> I would expect to get the following:
>
> The new Intel Core 2 Duo Processor Technology T8300
>
> but i get
>
> The new Intel Core 2 Processor Technology Duo Processor Technology T8300
>
> I can see why its doing it, reading the string in and making the
> replacement but then reading the string in for the next pattern, but i
> don't want it to do this. How do i stop preg_replace from reading in the
> same part of the string that has been replaced already?
>
> (it's a bad day! :( )
>
--
View this message in context:
http://www.nabble.com/preg_replace-strange-behaviour%2C-duplicates-tp1900116
6p19027490.html
Sent from the PHP - General mailing list archive at Nabble.com.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
No virus found in this incoming message.
Checked by AVG - http://www.avg.com <http://www.avg.com/>
Version: 8.0.138 / Virus Database: 270.6.4/1617 - Release Date: 17/08/2008
12:58