You are here: Re: [PHP] Re: Substr by words « PHP « IT news, forums, messages
Re: [PHP] Re: Substr by words

Posted by Gustavo Narea on 10/31/05 14:47

Hello, Marcus.

No, you are right. Your script is better.

I just forgot something I learned about REGEXES: The REGEX engine is
eager. Thus, in this case, It's not necessary to use the caret. The
REGEX engine will start from the first word It finds.

I would use yours ;-).

Best regards,

Gustavo Narea.
PHP Documentation - Spanish Translation Team.
Valencia, Venezuela.

Marcus Bointon wrote:
>
> On 31 Oct 2005, at 03:29, Gustavo Narea wrote:
>
>> I think It is OK what I said about the caret, but what we need to
>> change is the position of \W*:
>> Your suggestion: /(\b\w+\b\W*){1,$MaxWords}/
>> My suggestion: /^(\W*\b\w+\b){1,$MaxWords}/
>>
>> We need the *first* ($MaxWords)th words.
>
>
> I makes no difference - they will both work. Mine doesn't care where
> the first word starts because it doesn't use ^, and yours doesn't care
> where the first word starts because it's got ^ followed by \W*. Your
> overall match will end up with leading spaces, mine will end up with
> trailing spaces - the subsequent trim fixes them both. I like mine
> because it has 1 less char ;^)
>
> Ultimately, if it works for you, great!
>
> Marcus

 

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

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