PHP Article Summary Algorithm

Soldato
Joined
12 Jun 2005
Posts
5,361
Hi there,

I was wondering if anyone knows of a good algorithm for creating a summary of an article.

Basically I want to select the first section of full-words that does not go over [y] characters.

Thanks.
 
Perfect Thanks.

---

Instead of starting a new thread.

Does anyone know the preg_replace code so i can get rid of everything enclosed in square brackets, including the brackets themselves.

Thanks.
 
if you've got time/can be bothered, could you explain what the individual elements of that do? I'm not too bad with regular expressions, but I don't even know where to start with that!!
 
should help explain it..

Code:
/
  (
    \[
      [
        ^\[\]
      ]
      +
    \]
  )
/

1st is the opening delimeter, you probably know about these.
2nd is opening of a group
3rd is the escaped opening square bracket; so that the regex engine takes it as a literal.
4th is the opening square bracket (non-escaped) to indicate we are opening a selection of character patterns.
5th is the pattern of what we want to match within the square brackets; we tell it to match everything except for square brackets (when in a selection '^' is 'negate',) because we are using them as tokens.
6th is the closing square bracket (un-escaped) to indicate the pattern for characters has ended.
7th is the symbol to inicate we must match one or more of these patterns; else it would match "nothing" or "anything" to the pattern and we cold end up with the entire string being replaced.
8th is the closing group bracket
9th is the closing delimeter.

Now that I think of it some more, the group may be uneccessary.
 
Back
Top Bottom