Reply to Re: regex/preg_replace? How do I do this?

Your name:

Reply:


Posted by gosha bine on 06/04/07 13:00

On 04.06.2007 14:52 Pavel Lepin wrote:
> GoL <usenet@^^.wwwspace.net._nospam_^^> wrote in
> <j5v763posshgstkulnj9rbvgfoabmh14qf@4ax.com>:
>> So if I have the string:
>>
>> "some text here 1234567890 more text 0987654321 and more
>> text"
>>
>> I want it replaced with:
>>
>> "some text here 123###7890 more text 098###4321 and more
>> text"
>
> pavel@debian:~/dev/php$ cat r.php
> #!/usr/bin/php
> <?php
> $str =
> '"1111111111 some text here 1234567890, more text ' .
> '0987654321 and more text 2222222222"' ;
> echo (
> preg_replace (
> '/([\W^]\d{3})\d{3}(\d{4}[\W$])/' ,
> '\\1###\\2' ,
> $str ) .
> "\n" ) ;
> ?>
> pavel@debian:~/dev/php$ ./r.php
> "111###1111 some text here 123###7890, more text 098###4321
> and more text 222###2222"
> pavel@debian:~/dev/php$
>

Pavel, [\W$] doesn't mean "non-word or end of line" as you seem to
think. Metachars don't work in character classes.


--
gosha bine

extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok

[Back to original 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

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