You are here: preg_replace(...) looking for an exact number « All PHP « IT news, forums, messages
preg_replace(...) looking for an exact number

Posted by FFMG on 08/15/06 07:17

Hi,

I have a bunch of strings like
$txt = 'aaa1bbbb';
Or
$txt = 'aaaaaa12bbbb';
Or
$txt = 'aaaaaa123bbb';

And I want to search and replace special cases and for unique numbers.

$txt = preg_replace( "/a{0,10}1/", "ccc", $txt );

Because I don't know the number of leading 'a' I want to use
preg_replace(...)

But with the example above 'aaaaaa12bbb' would become 'ccc2bbb' and
'aaaaaa123bbb' would become 'ccc23bbb'. That is not correct as I was
only looking for number '1'.

I want to replace exactly number '1' and not number '123' because in my
case 'aaaa1' is not the same as 'aaaa123'

So basically I need to search and replace an exact number, (because 10
is not the same as 100 for example).

How can I do that?

Many thanks.

FFMG

 

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

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