Search results: 9 words bef. keyword, 9 words after keyword |
[eluser]Derek Allard[/eluser]
let me also point out the EllisLab Developer guidelines which will be really handy here.
[eluser]Bramme[/eluser]
[quote author="Derek Allard" date="1212526510"]Thanks Bramme. Good start, but I think there's some room for improvement here. I'd also like to solicit the whole community to give thoughts. Anyone have anything to add? For one, CI already has a highlight function in the text helper, we should probably use it and not a regex. Anyone else? Let's keep em coming.[/quote] -the highlight boolean could be changed to an integer: 0 = false, 1 = cut off from last space in the string (resulting in lesser characters left and right than boundary) or 2 = keeping the cut off words complete, resulting in more characters left and right than boundary. - I'm too new to CI to know anything about that highlight thing. I'll check it out. - Add ... to beginning and end. (maybe optional? Though that would make a lot of variables) -solution for lots of variables: enter array for the parameters. - possibility to add first and last $boundary (or another number) characters of $text in the excerpt too. - change $boundary to select amount of words, not characters.
[eluser]Rubiz'[/eluser]
Well guys, I'm not "mature" enough to give you ideas, I'll be waiting the result happy for help CI to grow on new functions, accidentally
[eluser]Rick Jolly[/eluser]
Edit: Scratch this - it's about 100 times slower than Bramme's. A couple of errors to mention though: 1) Oops, I have mixed up the $text and $phrase parameters. 2) Bramme's version doesn't seem to include enough words. Here's my attempt, roughly using the method I described above. I didn't include the $highlight parameter because it's easy enough to run the result through "highlight_phrase()" and the parameter didn't describe HOW to highlight. There would need to be 2 parameters for highlight as in "highlight_phrase()". Code: function excerpt ($text, $phrase, $boundary) Examples: Code: $phrase = "Lorem ipsum dolor sit amet, consectetur adipisicing elit.";
[eluser]Popcorn[/eluser]
Here's my attempt Derek, Code: function excerpt ($text, $phrase, $boundary = 10, $words = false) Did a quick benchmark Word Mode 100 Req : 0.001465 1,000 Req : Total Time : 0.013749 10,000 Req : Total Time : 0.134911 |
Welcome Guest, Not a member yet? Register Sign In |