You are here: Re: ereg_replace question « PHP Programming Language « IT news, forums, messages
Re: ereg_replace question

Posted by Andy Jeffries on 05/22/06 16:57

On Thu, 18 May 2006 20:56:59 -0500, Alan Little wrote:
> Carved in mystic runes upon the very living rock, the last words of Andy
> Jeffries of comp.lang.php make plain:
>
>> Yes. The - sign isn't listed in the range (i.e. it would be [^0-9.\-])
>> so it will remove it from the output
>
> In brackets, you only escape the [] characters themselves. Your expression
> will allow the \ character in the string.

I appreciate your enthusiasm but did you actually test this before trying
to correct me ;-)

$ cat test.php
<?php print preg_match("/[\-]/", '\\')."\n"; ?>
$ php test.php
0

According to your login, the \ in the string should have matched against
either "\ or -", but unsurprisingly it didn't.

However, you do make the good point that you don't *need* to escape the -,
I just do it for readability so there's no mistaking that I meant a
literal dash and not part of a range that I forgot to complete.

Cheers,


Andy

--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos

 

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

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