You are here: Re: regular expression problem (preg_replace) « PHP Programming Language « IT news, forums, messages
Re: regular expression problem (preg_replace)

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация