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
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,
On 30 Oct 2005, at 06:22, Gustavo Narea wrote:
$replacement = ereg_replace (^([[:space:]]*[^[:space:][:cntrl:]]+)
{1,$MaxWords}, ,$MyOriginalString);
echo substr( $MyOriginalString, 0, ($replacement) ? -strlen
($replacement) : strlen($MyOriginalString));
You could get the regex to do the
Hello.
Marcus Bointon wrote:
On 30 Oct 2005, at 06:22, Gustavo Narea wrote:
You could get the regex to do the search and the extraction in one go:
$MyOriginalString = This is my original string.\nWhat do you think
about this script?;
$MaxWords = 6; // How many words are needed?
$matches =
Other mistake in my last script.
Gustavo Narea wrote:
?php
$MyOriginalString = This is my original string.\nWhat do you think
about this script?;
$MaxWords = 6; // How many words are needed?
$replacement = preg_match(/^(\W*\b\w+\b){1,$MaxWords}/, '',
$MyOriginalString);
$result = substr(
On 30 Oct 2005, at 15:35, Gustavo Narea wrote:
I think that trim($matches[0]) will return the whole string with no
change.
No, it will return the entire matching pattern, not just the sub-
matches. I added the trim to remove any leading space, and there will
nearly always be a trailing
Hello, Marcus.
Marcus Bointon wrote:
On 30 Oct 2005, at 15:35, Gustavo Narea wrote:
I think that trim($matches[0]) will return the whole string with no
change.
No, it will return the entire matching pattern, not just the sub-
matches. I added the trim to remove any leading space, and there
7 matches
Mail list logo