Re: [PHP] Adding text before last paragraph

2007-08-28 Thread Dotan Cohen
On 28/08/07, Brian Rue <[EMAIL PROTECTED]> wrote: > Sure, I'll break it apart a little: Er, wow, thanks. Lots of material here... > '{(?=|\s)(?!.*|\s)))}is' > > $regex = '{' . // opening delimeter > '(?=' . // positive lookahead: match the beginning of a position >

Re: [PHP] Adding text before last paragraph

2007-08-27 Thread Richard Lynch
On Mon, August 27, 2007 5:45 pm, Dotan Cohen wrote: > Thank you Brian. This most certainly works. I'm having a very hard > time decyphering your regex, as I'd like to learn from it. I'm going > over PCRE again, but I think that I may hit google soon. Thank you > very, very much for the working code

Re: [PHP] Adding text before last paragraph

2007-08-27 Thread Richard Lynch
On Mon, August 27, 2007 1:46 am, Dotan Cohen wrote: > On 27/08/07, Richard Lynch <[EMAIL PROTECTED]> wrote: >> On Sun, August 26, 2007 3:41 pm, Dotan Cohen wrote: >> > I have a string with some HTML paragraphs, like so: >> > $text="First paragraph\nMore text\nSome more >> > text\nEnd of story"; >

RE: [PHP] Adding text before last paragraph

2007-08-27 Thread Brian Rue
h, the replacement string gets inserted at the matched position. I hope that made at least a little bit of sense :) If you're doing a lot of regex work, I would strongly recommend reading the book Mastering Regular Expressions by Jeffrey Friedl... it's very well written and very helpful. -

Re: [PHP] Adding text before last paragraph

2007-08-27 Thread Dotan Cohen
On 27/08/07, Brian Rue <[EMAIL PROTECTED]> wrote: > Dotan, try this: > > $text="First paragraph\nMore text\nSome more > text\nEnd of story"; > > $story = preg_replace('{(?=|\s)(?!.*|\s)))}is', "new > paragraph goes here\n", $text); > > This matches a position that has an opening tag (with or witho

Re: [PHP] Adding text before last paragraph

2007-08-27 Thread Brian Rue
Dotan, try this: $text="First paragraph\nMore text\nSome more text\nEnd of story"; $story = preg_replace('{(?=|\s)(?!.*|\s)))}is', "new paragraph goes here\n", $text); This matches a position that has an opening tag (with or without parameters), which is NOT followed anywhere in $text by anothe

Re: [PHP] Adding text before last paragraph

2007-08-26 Thread Dotan Cohen
On 27/08/07, Richard Lynch <[EMAIL PROTECTED]> wrote: > On Sun, August 26, 2007 3:41 pm, Dotan Cohen wrote: > > I have a string with some HTML paragraphs, like so: > > $text="First paragraph\nMore text\nSome more > > text\nEnd of story"; > > > > I'd like to add an image before the last paragraph. I

Re: [PHP] Adding text before last paragraph

2007-08-26 Thread Richard Lynch
On Sun, August 26, 2007 3:41 pm, Dotan Cohen wrote: > I have a string with some HTML paragraphs, like so: > $text="First paragraph\nMore text\nSome more > text\nEnd of story"; > > I'd like to add an image before the last paragraph. I know that > preg_replace can replace only the first n occurrences

[PHP] Adding text before last paragraph

2007-08-26 Thread Dotan Cohen
I have a string with some HTML paragraphs, like so: $text="First paragraph\nMore text\nSome more text\nEnd of story"; I'd like to add an image before the last paragraph. I know that preg_replace can replace only the first n occurrences of a string, but how can I replace the _last_ occurrence of a