|
Posted by Curtis on 01/04/07 10:36
<?php
$regex = '
/
([^i]+) # product name before i. You could also negate \s to
validate, if necessary
i+(?:\b|$) # one or more is before a word boundary or end of line
/x';
$product = preg_replace($regex, '$1', $product);
?>
Just tested it, and it seems to work how the OP specified. This will
replace all i's following the product name:
$p = '320i 320ii 400 555iiii';
Becomes
320 320 400 555
Curtis
On Jan 3, 7:37 am, "monomaniac21" <mcyi2...@googlemail.com> wrote:
> hi all
>
> using preg_replace
>
> how can i replace the letter i in a string with nothing (delete it)
> when it is the last letter or it is followed by an i?
>
> i have products that are listed in a db with i or ii as in 320ii and i
> want to strip out the i's at the end when displaying the product name
>
> thanks
>
> marc
[Back to original message]
|